Jump to content

[SOLVED] TIMESTAMP won't generate a date and time in database


twilitegxa

Recommended Posts

I have a field set to TIMESTAMP in my table and have it set to ON UPDATE CURRENT_TIMESTAMP for the attribute and CURRENT_TIMESTAMP for the default, but everytime I submit the form (it's a guestbook form), I want it to automatically enter inot my database what time the post was submitted, but right now all it is submitting is zeros. Can anyone tell me what I'm doing wrong? I'm using a bundled program named WampServer, if anyone's familiar.

Link to comment
Share on other sites

I know how to write some queries, but I am new to MySQL, so I'm a little unsure about some of the queries. I don't quite understand the timestamp one.

 

I am using WampServer, like I said, and it lets you name your table and then add the fields to the table with the different parts like the type and stuff like that. I have it set to timestamp, and I have ON UPDATE CURRENT_TIMESTAMP and CURRENT_TIMESTAMP set, but when I enter a record with my form, it saves a blank or all zeros date and time. I can't figure out what I'm doing wrong. Do I need to have the form send the timestamp to my database? Or will it automatically do that when a recrd is submitted? Because right now I just have the other fields that the user fills in.

Link to comment
Share on other sites

Let's take it step by step.

 

Go to phpMyAdmin, select a database and create new table with three fields

 

Call the first field ID, set its type to INT(10), select attributes to 'UNSIGNED', don't set default value, set additional as auto_increment, and select radiobutton under the icon with key (primary key)

 

Call the second one TS, set it type to TIMESTAMP, now in the 'default' column a checkbox should appear with CURRENT_TIMESTAMP next to it. Check it.

 

Call the third field 'value', set it to VARCHAR(20)

 

 

After creating this table, add new row to it. Don;t enter anything into ID nor TS, just enter value.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.