jeff5656 Posted July 14, 2009 Share Posted July 14, 2009 If this date field is blank $stentrev = date("Y-m-d", strtotime($_POST['stent_rev'])); it gets stored as 1969-12-31 How do keep it blank if the field is blank? If this is not possible, how do you guys handle a blank date field on a form? Link to comment https://forums.phpfreaks.com/topic/165875-blank-datefield-or-date-showing-1969/ Share on other sites More sharing options...
celsoendo Posted July 14, 2009 Share Posted July 14, 2009 SANITIZE get/post data BEFORE using them! NEVER (ever!) use get/post/cookie data without sanitize them before! Don't trust your visitors, don't trust on what they are typing, don't trust on what they're not typing, don't trust nobody! Assuming that your date column accepts NULL, you can make something like this (not exactly this, but just an example): if (isset($_POST['stent_rev']) && function_to_validate_post_entry($_POST['stent_rev'])) { $stentrev = date("Y-m-d", strtotime($_POST['stent_rev'])); } else { $stentrev = ''; } $sql = sprintf("INSERT INTO table (date_column) VALUES (%s)", (($stentrev) ? "'". $stentrev ."'" : "NULL")); ... ... Link to comment https://forums.phpfreaks.com/topic/165875-blank-datefield-or-date-showing-1969/#findComment-874943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.