UPDATE: The code above was borked in that leaving the field blank would always fail. I at least fixed that:
Code:
$must_match = "^[0-9]{4}\-[0-9]{2}\-[0-9]{2}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}$";
if((preg_match($must_match, $dte) && $dte) || (!$dte)) {
if(!$dte) {
$query = "INSERT INTO $table VALUES ('', NOW(), 'ajgraves', '$post');";
} else {
$query = "INSERT INTO $table VALUES ('', '$dte', 'ajgraves', '$post');";
}
} else {
die("ERROR: You entered an invalid date");
}
mysql_query($query);
But if I actually enter a date, the correct format fails (so do incorrect formats, which is the intended effect
)
I'm thinking it has to do with maybe the way I check for the space? "\ " perhaps isn't the best way. Maybe someone more versed in this can help me