我使用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);
}
答案 0 :(得分:1)
在WHERE clause
UPDATE ... ,email = ?, WHERE id = ?
^
删除它。