开发者

Problem with insertion query using foreach loop

开发者 https://www.devze.com 2023-03-20 06:30 出处:网络
I am using foreach loop for insertion query. At the same time I am matching value if those are exist in database or not. If value exist than I want to skip that particular key and than move to next ke

I am using foreach loop for insertion query. At the same time I am matching value if those are exist in database or not. If value exist than I want to skip that particular key and than move to next key value to insert. Again it check if value exist or not than save record if values are not exist in database.

I have used following approach to do this.

foreach( $inputs as $key => $value) {
if ($key == 'empty') continue;
    $check=mysql_query("select * from from t_atc_list where s_title='$key' and r_name='$value'");

    if(mysql_num_rows($check)!=0){ continue;        }
    $result = mysql_query("INSERT into t_atc_list(a_name, s_title, r_name) values('$album','$key', '$value')")or die(mysql_error());开发者_Python百科
    echo "<strong>$key</strong> Singer <strong>$value</strong></br>";

}

NOTE : (1). Values are inserting if value are already present that is duplicate entries. (2). I am getting warning " mysql_num_rows(): supplied argument is not a valid MySQL result resource in..."


You have the word "from" twice in your first query, which causes your query to have invalid syntax and return (bool)false instead of a MySQL resource. So mysql_num_rows($check) throws an error and the if statement always evaluates to false.

Change:

select * from from t_atc_list

To:

select * from t_atc_list
0

精彩评论

暂无评论...
验证码 换一张
取 消