Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update mysql timestamp

I have a table with a field:

'last_modified - timestamp NOT NULL'

  • I set the default value to the current timestamp. However this only works when updating or inserting from phpMyAdmin and not from my script.

I have tried

$sql = sprintf("UPDATE %s SET timestamp=now(), %s WHERE id='%s'", $table, $implodeArray, $_POST['id']);

and it still doesnt seem to work. How can I make the timestamp update when I update or insert by table from a script?

Also heres a sample of the scripts output:

UPDATE about SET timestamp=now(), page_header = 'Page header goes here', sub_header = 'Sub header goes here', content_short = 'This is where a short description of the about page goes', content = 'This is where the full content description goes' WHERE id='1'

like image 311
Alex Avatar asked Mar 03 '26 18:03

Alex


1 Answers

May be I misread,but your column name is last_modified (typed timestamp), so the query should be:

UPDATE about SET last_modified=now(), 
page_header = 'Page header goes here', 
sub_header = 'Sub header goes here', 
content_short = 'This is where a short description of the about page goes', 
content = 'This is where the full content description goes' 
WHERE id='1'
like image 121
Ivan Buttinoni Avatar answered Mar 06 '26 07:03

Ivan Buttinoni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!