aaricwon Posted February 27, 2008 Share Posted February 27, 2008 I have a form I made to submit news. It is simple... Subject, Short Story, Full Story, and I would then like the date to be posted. Can anyone tell me how to make that entered to the database automatically? Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/ Share on other sites More sharing options...
drisate Posted February 27, 2008 Share Posted February 27, 2008 you can add $date=date("m-d-Y"); or you can use the build in MySQL date Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/#findComment-477678 Share on other sites More sharing options...
cyrixware Posted February 27, 2008 Share Posted February 27, 2008 You can add field in your table. Let say date_posted (use TIMESTAMP) automatically after you click submit, the current time and date of the system inserted also. Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/#findComment-477704 Share on other sites More sharing options...
bpops Posted February 27, 2008 Share Posted February 27, 2008 you can add $date=date("m-d-Y"); or you can use the build in MySQL da To add to this, use $date=date("Y-m-d"); and then you can add this string to a type 'date' column of your table. Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/#findComment-477718 Share on other sites More sharing options...
cyrixware Posted February 27, 2008 Share Posted February 27, 2008 ======|RowID|Subject|SStory|FStory|DatePosted========= =============================================== RowID = Primary, Auto_increment DatePosted = TYPE:timestamp I think this is the very easiest way to insert automatically the current time and date after you have posted. But there are so many ways.. Regards Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/#findComment-477725 Share on other sites More sharing options...
timmy0320 Posted February 27, 2008 Share Posted February 27, 2008 You know, I don't know whats up but my TIMESTAMP to current_timestamp never works. My INSERT stops working so I had to do a format in PHP to get inserted into an INT. Maybe I'm just doing it wrong. Do I put anything in the INSERT or put a NULL or NOW() or don't even put a value for the TIMESTAMP. None of them work for me Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/#findComment-477728 Share on other sites More sharing options...
cyrixware Posted February 27, 2008 Share Posted February 27, 2008 hi, no need to put a value for a timestamp in the structure of your table. ex. namefield simply use timestamp. so in your php page no need to insert date to save because automatically the current time and date of your system save in your dbase after you have inserted some data's. but make sure try to create field for your primary key. ex rowid TYPE int, auto_increment. ========= |rowid| name | date_posted | ========== 001 John 00,00,00 00:00:00 002 Allan 00,00,00 00:00:00 ========================================== Link to comment https://forums.phpfreaks.com/topic/93256-automatically-inserting-timedate-into-database/#findComment-477730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.