Assume that I’m adding the date / time into a mysql database and have the following (small for once) chunk of code.
<input type="text" name="date">Leave time null for current<br />
<input type="Submit" name="submit" value="submit">
The Following is the form that catches that
$radate=$_POST['date'];
if ($radate=="")
$radate = date('Y-m-d H:i:s');
else {}
I’ve tried entering “2011-08-14 19:15:25” and it has returned all 0’s, can someone help me out with this? Thanks a ton!
You would probably be better off using
strtotime()to validate the date/time submitted, if it’s a freeform date entry field especially. Otherwise, someone may miss-enter a date/time and unexpectedly have it use the current date/time instead.http://codepad.org/x2eZay0Q
If you used dropdowns, and the time was not a factor, you could also use
checkdate(), although from your example it looks like you do need the time.However, what you have posted should work. Here is an example using your date you provided:
http://codepad.org/BK1yqyMT
(And here without fixing the
ifblock: http://codepad.org/p3CfmOJK)