Jump to content

Recommended Posts

Hi, I am trying to set a timestamp when info is submitted into the table I have set up in the MySQL database. I am not sure what to add to the INSERT statement to do this. The timestamp field is set up IN mySQL like so:

]code]

`submit_timestamp` datetime NOT NULL default '0000-00-00 00:00:00',

[/code]

 

and my SQL is currently:

 

$sql="INSERT INTO Responses (`editor_name`,`Answer1`,`Answer2`,`Answer3`,`Answer4`,`Answer5`,`Answer6`,`Answer7`,`Answer8`,`Answer9`) VALUES ('$editor_name','$A1','$A2','$A3','$A4','$A5','$A6','$A7','$A8','$A9')"; 

Link to comment
https://forums.phpfreaks.com/topic/191792-need-help-with-sql-error/
Share on other sites

I think I might be misunderstanding what I need to do, I tried this but get an error.

 

$sql="INSERT INTO Responses (`editor_name`,`Answer1`,`Answer2`,`Answer3`,`Answer4`,`Answer5`,`Answer6`,`Answer7`,`Answer8`,`Answer9``submit_timestamp` datetime NOT NULL default CURRENT_TIMESTAMP, VALUES $sql="INSERT INTO Responses (`editor_name`,`Answer1`,`Answer2`,`Answer3`,`Answer4`,`Answer5`,`Answer6`,`Answer7`,`Answer8`,`Answer9`) VALUES ('$editor_name','$A1','$A2','$A3','$A4','$A5','$A6','$A7','$A8','$A9')"; 

I have left the timestamp the whole timestamp column out in the insert line.

 

$sql = "INSERT INTO $dbtable (user_name, password, name, user_level, settings_day_start, settings_day_stop) VALUES ('$user_name', '$md5_pasword', '$name', '$user_level', '-1', '7')";

 

My table looks like this:

ID | NAME | USER_NAME | PASSWORD | USER_LEVEL | MADE | SETTINGS_DAY_START | SETTINGS_DAY_STOP

 

Where MADE is my timestamp column. So MySQL generates the timestamp for me.

@mchl using php myadmin, I don't see an option to change the default to CURRENT_TIMESTAMP. There is an option to change the function to CURTIME, would this do the same thing?

 

@fesan in your VALUES what does listing '-1', '7' do?

 

thanks for the responses!

@mchl using php myadmin, I don't see an option to change the default to CURRENT_TIMESTAMP. There is an option to change the function to CURTIME, would this do the same thing?

 

Click 'Structure' tab not 'Insert' tab. Click the pencil icon next to your timestamp column and selecr CURRENT_TIMESTAMP in 'Default' field.

OK, I see now. I didn't have set to TIMESTAMP, which I do now, and also to CURRENT_TIME, however when a record is inserted into the table, the timestamp field doesn't update. My structure is now:

 

`submit_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,

output below

 

CREATE TABLE `Responses` (\n  `editor_name` text,\n  `Answer1` text,\n  `Answer2` text,\n  `Answer3` text,\n  `Answer4` text,\n  `Answer5` text,\n  `Answer6` text,\n  `Answer7` text,\n  `Answer8` text,\n  `Answer9` text,\n  `submit_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,\n  `user_id` int(11) NOT NULL auto_increment,\n  PRIMARY KEY  (`user_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8

I had forgotten to take out the value I was trying in SQL, so now it works now. One for small thing though. The value displayed on the server is three hours behind, what I want it to display (west coast time vs. east coast time). Anyway to have it set (+3 hours)?

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.