Harry
Harry

Reputation: 167

PHP MYSQL Update multiple fields including DATETIME field

I can update the field 'delivered' from 0 to 1 no problem but when I try to update 'delivered_time' nothing happens in the database. This may be to do with the way I am writing the code but If anybody could help I would really appreciate it, thanks!

if (isset($_POST['delivered']) === false) {
                mysql_query("UPDATE `listings` SET `delivered_time` = '{$date->format('Y-m-d H:i:s')}' AND `delivered` = 1 WHERE `order_id` = $order_id");
}

I have also tried this but this did not work either

if (isset($_POST['delivered']) === false) {
                    mysql_query("UPDATE `listings` SET `delivered_time` = NOW() AND `delivered` = 1 WHERE `order_id` = $order_id");
} 

My MYSQL database is set to have 'delivered' defined to 0 and is stored as an INT value. The 'delivered_time' field is stored as a DATETIME value in the database.

Upvotes: 0

Views: 1589

Answers (2)

Rizwan Sultan
Rizwan Sultan

Reputation: 187

Try this code

<?php

if (isset($_POST['delivered']) === false) {
    mysql_query("UPDATE `listings` SET `delivered_time` = NOW(),`delivered` = 1 WHERE `order_id` = ".$order_id);
}
?>

Upvotes: 2

Mark Baker
Mark Baker

Reputation: 212452

, not AND as the field separator; AND is used in WHERE clauses

UPDATE `listings` 
   SET `delivered_time` = '{$date->format('Y-m-d H:i:s')}',
       `delivered` = 1 
 WHERE `order_id` = $order_id

Upvotes: 3

Related Questions