Forum Moderators: open

Message Too Old, No Replies

Inserting date into mysql table

         

zulubanshee

12:55 am on Feb 3, 2009 (gmt 0)

10+ Year Member



I have a string '2009-01-20' I want to insert into a mysql table, but all dates are being inserted as 1969-12-31. I assume there is some conversion necessary. I tried:

$date = date('Y-m-d', $date);

but it does the same thing. The date will not necessarily be today.

zulubanshee

1:22 am on Feb 3, 2009 (gmt 0)

10+ Year Member



using php if that was not obvious. :)

sonjay

5:39 am on Feb 3, 2009 (gmt 0)

10+ Year Member



What's your query look like?

zulubanshee

5:55 am on Feb 3, 2009 (gmt 0)

10+ Year Member



$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$date = $year."-".$month."-".$day;

$sql = "insert into com_sales (sale_id, sales_rep, customer_name, customer_phone, dialer_or_email, payment_type)
values
(sale_id,'$sales_rep','$customer_name', '$customer_phone', '$dialer_or_email', '$payment_type', '$date')";

sonjay

12:51 pm on Feb 3, 2009 (gmt 0)

10+ Year Member



If you put this on the page:
echo $sql;
what do you get?

And if you run the sql, like this, what do you get:
$insert = mysql_query($sql) or die(mysql_error());

Is a MySQL error generated? If so, what does it say?

LifeinAsia

4:28 pm on Feb 3, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You're specifying 6 fields to insert, but 7 values. Most DBs would throw an error. If yours isn't, it's most likely just ignoring the 7th value.