【发布时间】:2015-07-21 07:48:02
【问题描述】:
这是我的代码:
$result = mysql_query("INSERT INTO clients (client_id, name, surname, tel1,tel2,id_num,address)
VALUES ('" .$updating_id . "','" .$updatedName1 . "','" .$updatedName1 . "', '" .$updatedSurname1
. "', '" . $updatedTel1 . "', '" .$updatedTel2 . ", '" .$updatedId_num1. "', '" .$updatedAddress1.
") ON DUPLICATE KEY UPDATE name='" . $updatedName1 . "', surname='" . $updatedSurname1 . "',
tel1='" . $updatedTel1 . "', tel2='" . $updatedTel2 . "', id_num='" . $updatedId_num1 . "',
address='" .$updatedAddress1 . "'");
if(mysql_query($result))
{ echo $updatedName1," ", $updatedSurname1, " updated successfully ";
}
else {
echo mysql_error();}
}
我注意到mysql_query("INSERT INTO 上的第一句话...
以VALUES ('" .$updating_id . "'... 声明的第一个引号结束,但我引用的方式是我的示例中的方式,我已经评估过。
【问题讨论】:
-
错误说明了什么?
-
不要再使用已弃用的
mysql_*API。将mysqli_*或PDO与准备好的语句一起使用。 -
@kristian 错误是'查询为空'
-
你打电话给
mysql_query两次并在$result上打电话毫无意义。 -
使用
if($result)而不是if(mysql_query($result))