0

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.

1
  • You can't use ANDwhen using SET, you have to use comas. Commented Jan 1, 2014 at 12:41

2 Answers 2

3

, 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
Sign up to request clarification or add additional context in comments.

Comments

2

Try this code

<?php

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.