在MySQL查询中获取qoutes错误

时间:2015-07-21 07:48:02

标签: php html mysql apache

这是我的代码:

$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 . "' ...语句的第一个引用结束,但我引用的方式是我的例子中的一个,我已经评估了。

1 个答案:

答案 0 :(得分:2)

使用if($result)代替if(mysql_query($result))。 thx @Vinie

您在VALUES声明中遗漏了两个简单的引号:

$updatedTel2 . "'
$updatedAddress1."'

您需要查看mysql_real_escape_string();或至少使用PDO:)