Reputation: 9076
I am working on inserting blogpost in mysql database with php. Along with the data I want to insert the time when the post is submitted. For this I have created a database with following data types:
postid(INT), title(varchar), Post(longtext), Userid(INT), posted(TIME_STAMP)
the code for insertion is :
$db->insert('userpost',array('title'=>$title,
'post'=>$content,
'userid'=>$userData->id,
'posted' => time(),
))
But the problem is after insertion the "POSTED" field shows all zeros. Why this problem is happening and how to solve this?
Upvotes: 0
Views: 40
Reputation: 71
You can set the Current TimeStamp to be taken for each new row added in PHPMyAdmin
`posted` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
Upvotes: 1
Reputation: 1713
open your database editor and set "posted" field default value to CURRENT_TIMESTAMP
Change insert query to this
$db->insert('userpost',array('title'=>$title,'post'=>$content,'userid'=>$userData->id))
Upvotes: 1