foreach($states_to_add as $item) { $dupesql = "SELECT COUNT(*) FROM table WHERE ( name = '$name' AND description = '$description' AND manufacturer = '$manufacturer' AND city ='$city' AND price = '$price' AND enddate = '$end_date' )"; $duperaw = MysqL_query($dupesql); if($duperaw > 0) { echo nl2br("$name already exists in $city \n"); } else { $sql = "INSERT INTO table (..... (here go the values to be inserted) ....
在运行此检查之前定义每个值,我的结果总是在项目已存在时返回.我倾倒了“dupesql”并将命令复制/粘贴到PHPmyadmin中,后者返回计数0.