user1532468
user1532468

Reputation: 1753

Mysql syntax error on update

I have been staring at this query for ages trying to figure out why I am getting the error as stated in the title and for the life of me cannot see hot to correct it. All fields are correct and all POST values are being posted correctly. I would be grateful if someone with fresh eyes could point out the error. Many thanks.

$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));

Upvotes: 0

Views: 96

Answers (2)

A. Colonna
A. Colonna

Reputation: 872

In your where it's not , it's and between the clauses:

$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));

Upvotes: 0

flyingfox
flyingfox

Reputation: 13506

You should use AND instead of , in WHERE

Change

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

to

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

Upvotes: 2

Related Questions