AL-zami AL-zami - 4 years ago 146
SQL Question

time_stamp data type prints all zero in mysql database when inserted

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 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 zeors .Why this problem is happening and how to solve this?

enter image description here

Answer Source

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))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download