this is a strange one.
I have a date, that is converted to mm-dd-yyyy
when posting it to mysql i have re-ordered it to yyyy-mm-dd
but yet it still will not insert
$date = date("Y-m-d", strtotime($_POST['leaving_date']) );
any advice? Cheers
EDIT
The actual query:
mysql_query("INSERT INTO booking_info (customer_id, booking_ref, date_of_travel) VALUES (".mysql_real_escape_string($_POST['customer_id']).", ".mysql_real_escape_string($rnd).", ".mysql_real_escape_string($date).")");
When you're adding a date, wrap it using double quotes, like a string.
mysql_query("INSERT INTO booking_info (customer_id, booking_ref, date_of_travel) VALUES (".mysql_real_escape_string($_POST['customer_id']).", ".mysql_real_escape_string($rnd).", \"".mysql_real_escape_string($date)."\")");
Looking at your editted question, it appears you are lacking single quotes around your date. Also, it may be slower, but you can always have MySQL do the formatting for you. Depending on what extension you are using, you can do something like this:
INSERT ... VALUES (STR_TO_DATE('$phpDate', '%m-%d-%Y')), col2, ...)
You need to have single quotes around the date (and possibly the booking_ref if this is not an integer or other sort of numerical field.
Try this:
mysql_query("INSERT INTO booking_info (customer_id, booking_ref, date_of_travel) VALUES (".mysql_real_escape_string($_POST['customer_id']).", ".mysql_real_escape_string($rnd).", '".mysql_real_escape_string($date)."')");
your values are not wrap with single quotes.
mysql_query("INSERT INTO booking_info (customer_id, booking_ref, date_of_travel)
VALUES (
'".mysql_real_escape_string($_POST['customer_id'])."',
'".mysql_real_escape_string($rnd)."',
'".mysql_real_escape_string($date)."')");
mysql_query("INSERT INTO booking_info (customer_id, booking_ref, date_of_travel) VALUES (".mysql_real_escape_string($_POST['customer_id']).", ".mysql_real_escape_string($rnd).", '$date')");
try that one.... should fix the problem but not a good way to write sql... no need to call mysql_real_escape_string function on $date variable as your $date variable.
It should be mentioned that using PDO wouldn't give you these issues; let me illustrate:
// assuming $db is a PDO instance to your database
// prepare the statement
$stmt = $db->prepare('INSERT INTO booking_info (customer_id, booking_ref, date_of_travel) VALUES (:customer, :ref, :date)');
// execute the statement with your variables
$stmt->execute(array(
':customer' => $_POST['customer_id'],
':ref' => $rnd,
':date' => $date,
));
The proper quoting and escaping is done in the background; neat huh? :)