AL-zami
AL-zami

Reputation: 9076

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 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?

enter image description here

Upvotes: 0

Views: 40

Answers (2)

abhi
abhi

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

Alpesh Panchal
Alpesh Panchal

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

Related Questions