插入前检查重复

时间:2019-06-03 04:03:46

标签: php

我试图在插入数据库之前检查重复数据,但是,它仍然给我带来错误,我尝试了所有可能的方法,但是老实说我不知道​​我在哪里错过了它

$dupesql = "SELECT * 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 (mysql_num_rows($duperaw) > 0)

但是我一直得到这个结果

  

警告:mysqli_query()[function.mysqli-query]:在C:\ wamp \ www \ sug2019 \ form_processors \ dgs_processor.php中的空查询位于第52行

1 个答案:

答案 0 :(得分:1)

尝试使用mysqli而不是mysql来解决问题

$dupesql = mysqli_query($con,"SELECT * FROM table where name = '$name' AND description = '$description' AND manufacturer = '$manufacturer' AND city ='$city' AND price = '$price' AND enddate = '$end_date'");

if(mysqli_num_rows($dupesql)<=0){
// No duplicate data found 
}else{
// Duplicate Data found
}

在此$con中是您的连接文件变量

相关问题