更新时出现Mysql语法错误

时间:2018-06-15 09:46:37

标签: php mysql

我一直盯着这个查询多年来试图弄清楚为什么我会收到标题中所述的错误,而且我的生活中看不到热点来纠正它。所有字段都正确,所有POST值都正确发布。如果有新眼睛的人能够指出错误,我将不胜感激。非常感谢。

$id = $_POST['id'];
$rack = strtoupper($_POST['slot']);
$column = $_POST['column']; <---INT
$row = $_POST['row']; <---INT
$bay = $_POST['bay']; <---INT
$size = $_POST['size'];
$service = ucfirst($_POST['service']);
$activity = ucwords($_POST['activity']);
$dept = $_POST['dept'];
$company = $_POST['company'];
$address = ucwords($_POST['address']);
$user = ucwords($_POST['user']);
$box = $_POST['item

“];

$query = "UPDATE `boxes` SET `rack` = '".$rack."',`column` = $column,`row` = $row,`bay` = $bay,`status` = '1',`customer` = '".$company."', `department` = '".$dept."',`request` = 0,`custref` = '".$box."',`size` = '".$size."',`authorisation` = '".$user."' WHERE `department` = '".$dept."',`customer` = '".$company."',`custref` = '".$box."'";
      mysqli_query($conn, $query) or die('Error, box action failed'. mysqli_error($conn));

2 个答案:

答案 0 :(得分:2)

您应该在AND

中使用,代替WHERE

更改

WHERE `department` = '".$dept."',`customer` = '".$company."',`custref` = '".$box."'";

WHERE `department` = '".$dept."' AND `customer` = '".$company."' AND `custref` = '".$box."'";

答案 1 :(得分:0)

在你不在的地方,它和条款之间:

$query = "UPDATE `boxes` SET `rack` = '".$rack."',`column` = $column,`row` = $row,`bay` = $bay,`status` = '1',`customer` = '".$company."', `department` = '".$dept."',`request` = 0,`custref` = '".$box."',`size` = '".$size."',`authorisation` = '".$user."' WHERE `department` = '".$dept."' AND `customer` = '".$company."' AND `custref` = '".$box."'";
  mysqli_query($conn, $query) or die('Error, box action failed'. mysqli_error($conn));