Lambneck Posted May 5, 2008 Share Posted May 5, 2008 Hello, how can I collect the date of a form submission? I'm trying to log form entires by date in a database. theres no date field in the form. I just want to collect the date using php. Thanks, Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/ Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 <?php $handle = fopen('form_submissions.log'); $date = date(DATE_RFC822); fwrite($handle, "form submitted on $date\n"); fclose($handle); ?> Something like that would create a log and write dates to it. I guess you could run something like this every time the form is submitted. The file would like like this: form submitted on Mon, 15 Aug 2005 15:12:46 UTC form submitted on Mon, 16 Aug 2005 15:12:46 UTC form submitted on Mon, 16 Aug 2005 15:12:46 UTC form submitted on Mon, 17 Aug 2005 15:12:46 UTC etc.... Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533766 Share on other sites More sharing options...
Lambneck Posted May 5, 2008 Author Share Posted May 5, 2008 I just want to be able to $_POST the date to a mysql database but im new to php and dont know how. Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533850 Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 On the the php page just make the current time and add that into the database. $time = time(); Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533851 Share on other sites More sharing options...
realjumper Posted May 5, 2008 Share Posted May 5, 2008 I just want to be able to $_POST the date to a mysql database but im new to php and dont know how. On your form page...... form.htm <form name = "my_form" action ="insert.php" method = "post"> <input type="hidden" name="date_submitted" value="<?php echo date("jS F Y")?>"> </form> And on your insert to the db page...... insert.php <?php require('connect.inc'); $date_submitted = $_POST['date_submitted']; $query = "INSERT INTO table (id,date_submitted) VALUES ('','$date_submitted')"; mysql_query($query); ?> Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533862 Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 @realjumper: A user can change the timestamp then....just get the time on the PHP page. The .5 seconds that it takes for the PHP page to load with the time won't destroy you. Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533866 Share on other sites More sharing options...
realjumper Posted May 5, 2008 Share Posted May 5, 2008 @realjumper: A user can change the timestamp then....just get the time on the PHP page. The .5 seconds that it takes for the PHP page to load with the time won't destroy you. Yes I suppose so, but it's very unlikely a user would do that because they won't be aware of the collection of the date of submission...unless they are looking at the code Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533874 Share on other sites More sharing options...
DarkWater Posted May 5, 2008 Share Posted May 5, 2008 Anyone who would want to do it could. Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533877 Share on other sites More sharing options...
Lambneck Posted May 5, 2008 Author Share Posted May 5, 2008 I appreciate all the help I tried the following with no luck. i just want the date of the form entry to be collected when the form is submitted. if (isset($_POST['Submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $submission_date = datetime(); mysql_query("INSERT INTO $table (col_2, col_3, col_4, col_5, submission_date) VALUES ('$name', '$email', '$subject', '$message', '$submission_date')")or die(mysql_error()); $user = $_POST['name']; echo '<table id=table1><tr><td><b><font size=2>Thank you ' . $user . ', your information was was submitted.</font></b></tr></td>'; } ?> Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533933 Share on other sites More sharing options...
realjumper Posted May 5, 2008 Share Posted May 5, 2008 Change $submission_date = datetime(); to $submission_date = date("jS F Y"); see http://www.w3schools.com/php/php_ref_date.asp Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533954 Share on other sites More sharing options...
Lambneck Posted May 6, 2008 Author Share Posted May 6, 2008 I used: if (isset($_POST['Submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $submission_date = date("jS F Y"); mysql_query("INSERT INTO $table (col_2, col_3, col_4, col_5, submission_date) VALUES ('$name', '$email', '$subject', '$message', '$submission_date')")or die(mysql_error()); and it displays "0000-00-00" in the database how can I make it display something like this "Sun, 14 Aug 2005 16:13:03" ??? Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-533999 Share on other sites More sharing options...
realjumper Posted May 6, 2008 Share Posted May 6, 2008 I used: if (isset($_POST['Submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $submission_date = date("jS F Y"); mysql_query("INSERT INTO $table (col_2, col_3, col_4, col_5, submission_date) VALUES ('$name', '$email', '$subject', '$message', '$submission_date')")or die(mysql_error()); and it displays "0000-00-00" in the database how can I make it display something like this "Sun, 14 Aug 2005 16:13:03" ??? What 'type' is your submission_date field?.....int, varchar etc etc???? Here is a link to the PHP date & time formats http://www.wdvl.com/Authoring/Languages/PHP/Date_Time/ Link to comment https://forums.phpfreaks.com/topic/104264-solved-form-date/#findComment-534005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.