更新超过三行时mysqli stmt错误?

时间:2014-08-09 03:25:53

标签: php mysql mysqli

我使用mysqli语句更新总共15个输入。我测试了2,它工作,我测试了3条记录,它工作,所以我说添加更多,然后检查我的工作,我得到这个错误。当我刚刚更新公司名称和名字时,我没有收到此错误

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'You have an error     in your SQL syntax; check the manual that corresponds to your MySQL server version for the     right syntax to use near 'WHERE id = ?' at line 1' in /homepages/3/d300203244/htdocs/testphp/updatecustomer.php:23 Stack trace: #0 /homepages/3/d300203244/htdocs/testphp/updatecustomer.php(23): mysqli->prepare('UPDATE customer...') #1 {main} thrown in /homepages/3/d300203244/htdocs/testphp/updatecustomer.php on line 23

我的服务器正在运行php5.4和mysql5。

这是我的代码

<?php
if(isset($_POST['update']))
{mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
require ('dbconnect.php');
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id= $_POST['id'];
$company= $_POST['company'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];




$stmt = $con->prepare('UPDATE customer SET company = ?,firstname = ?,lastname = ?,phone = ?, fax = ?,email = ?, WHERE id = ?');
$stmt->bind_param('ssssssi', $company, $firstname, $lastname, $phone, $fax, $email, $id);
$stmt->execute();

echo 'Updated data successfully', PHP_EOL;

echo "Updated data successfully\n";
mysqli_close($conn);
}

1 个答案:

答案 0 :(得分:1)

WHERE clause

之前,您的查询中还有一个额外的逗号
UPDATE ... ,email = ?, WHERE id = ?
                     ^

删除它。