jassikundi Posted February 10, 2008 Share Posted February 10, 2008 Hi, I'm trying to create a form that captures users data and one of the fields are the time/date of when the user submitted the form, which I would like to record in mySQL. My column in mySQL is of the DATETIME type. Here is the PHP I'm using to acquire UK time. [pre]<?php echo $datetime = date("l, F j, Y, g:i a", time() - date("Z")) ?>[/pre] The variable I'm trying to post is $datetime however I'm registering 0000-00-00 00:00:00's in mySQL. Can someone please give me the correct php to use to get the UK time to be inserted in the mySQL database column. Please note I'm a novice at php and mysql, can some one tell me without going into to much detail? I've tried to read various websites offering info but still cant understand it. Regards Jassi Quote Link to comment https://forums.phpfreaks.com/topic/90416-posting-php-time-to-mysql/ Share on other sites More sharing options...
amites Posted February 10, 2008 Share Posted February 10, 2008 are you trying to set a certain time or current time? current can be added with the mySQL value now() if your trying to post a specific time then you're best start is by printing out the value and making sure it matches what you want it to be, that line looks a little off to me Quote Link to comment https://forums.phpfreaks.com/topic/90416-posting-php-time-to-mysql/#findComment-463531 Share on other sites More sharing options...
jassikundi Posted February 10, 2008 Author Share Posted February 10, 2008 Hi I'm trying to set the current time I've read about the now() value however how would I query to insert this into the database? I would like it to be stored in the time column. I'm currently adding the rest of the values of my form like this: [pre]//This gets all information from the form $title=$_POST['title']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $address=$_POST['address']; $town=$_POST['town']; $county=$_POST['county']; etc..[/pre] [pre]//Writes the information to the database mysql_query("INSERT INTO `contracts` VALUES ('$title', '$firstname', '$lastname', '$address', '$town', '$county', '$postcode', '$telephone', '$email', '$quotation', '$rangeselection', '$measurements', '$information', '$username')") ;[/pre] Regards Jassi Quote Link to comment https://forums.phpfreaks.com/topic/90416-posting-php-time-to-mysql/#findComment-463547 Share on other sites More sharing options...
jassikundi Posted February 11, 2008 Author Share Posted February 11, 2008 Hi, managed to post the current time using the now() however how can I make the time display in GMT format it seems to be an hour forward. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/90416-posting-php-time-to-mysql/#findComment-463932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.