HippoDuck
HippoDuck

Reputation: 2194

PHP / MYSQL Inserting current time to datetime

$newtime = date("Y-m-d H:i:s", time() + 600);
mysql_query("UPDATE rounds SET clock = $newtime WHERE `round`='$CurrentRound' ") or die(mysql_error()); //update DB 

This code is failing to add the current time (+10 mins) to the MySQL database.

The cell in the database is datetime format.

I had done this before, but upon rewriting the code, it has stopped working.

Upvotes: 0

Views: 445

Answers (2)

iam-decoder
iam-decoder

Reputation: 2564

change your query to this:

("UPDATE rounds SET `clock` = '$newtime' WHERE `round` = '$CurrentRound'")

Upvotes: 0

bear
bear

Reputation: 11605

You could use

UPDATE rounds SET clock = NOW() + INTERVAL 10 MIN WHERE round = '$CurrentRound'

To set the clock to 10 mins, per the time on the MySQL server.

Alternatively, you need to add ' around the $newTime variable

UPDATE rounds SET clock = '$newtime' WHERE round = '$CurrentRound'

Upvotes: 2

Related Questions