...

View Full Version : Date in Database Shows 0000-00-00



macleodjb
12-31-2007, 09:37 PM
Hi Guys,
How can i get my date to show properly in my sql database? I'm using php and have the following code.


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


If i output this code with echo to my browser i get "2008-02-01", so i know it's outputting correctly, but when i go to my database all i get is 0000-00-00.

Whats the deal?

Thanks in advance.

Fumigator
12-31-2007, 09:49 PM
Show us the code for your INSERT query. Tell us what data type your date column is (int, char, varchar, date, etc).

macleodjb
12-31-2007, 10:50 PM
The field in the database is a Date field.

Here's the insert query.



function addjob(){
$installdate = $_POST['year'];
$installdate = $installdate . "-" . $_POST['month'];
$installdate = $installdate . "-" . $_POST['day'];
$query = "INSERT INTO `jobs` (`jid`, `jobnumber`, `jobname`, `hand_off_meeting`, `hand_off_meeting_date`, `engineering_received`, `engineering_received_date`, `drawing_started`, `drawing_started_date`, `drawing_completed`, `drawing_completed_date`, `drawing_submitted`, `drawing_submitted_date`, `red_lines_received`, `red_lines_received_date`, `red_lines_started`, `red_lines_started_date`, `red_lines_completed`, `red_lines_completed_date`, `released_to_cutlisting`, `released_to_cutlisting_date`, `cutlisting_received`, `cutlisting_received_date`, `cutlisting_started`, `cutlisting_started_date`, `cutlisting_completed`, `cutlisting_completed_date`, `released_to_manuf`, `released_to_manuf_date`, `manuf_received`, `manuf_received_date`, `manuf_started`, `manuf_started_date`, `manuf_completed`, `manuf_completed_date`, `released_to_install`, `released_to_install_date`, `install_started`, `install_started_date`, `install_completed`, `install_completed_date`, `install_date`) VALUES (NULL, '" . $_POST['jobnum'] . "', '" . $_POST['jobname'] . "', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '" . $installdate . "')";
$result = @mysql_query ($query); //Run the query
}

GO ILLINI
12-31-2007, 11:20 PM
wow... from that query ide say that you may have miscounted your null's and are inserting null into the date field which would return a date with just 0's.
Just a tip:
Wouldn't it be easier(and much much cleaner) to just set the default in the database for all of those to be 'NULL'...? then you don't have to waste time entering anything into them with php.

-Adam

GJay
12-31-2007, 11:35 PM
you wouldn't even need to set defaults, null will be the default unless you speify otherwise. That is a ridiculous query, I'd consider having a separate table of all the 'events' personally...

macleodjb
12-31-2007, 11:45 PM
I don't know how you do that. I'm not that good at sql, or php for that matter. I have the fields set in the database to accept nulls if that's what you were referring to?

If i don't need to enter all those other fields on my insert query then how will the new insert query appear?



function addjob(){
$installdate = $_POST['year'];
$installdate = $installdate . "-" . $_POST['month'];
$installdate = $installdate . "-" . $_POST['day'];
$query = "INSERT INTO `jobs` (`jid`, `jobnumber`, `install_date`) VALUES (NULL, '" . $_POST['jobnum'] . "', '" . $_POST['jobname'] . "', '" . $installdate . "')";
$result = @mysql_query ($query); //Run the query
}


Is that correct? If so that only takes care of my sloppy coding, and it doesn't take care of my original problem. I know i didn't miscount the nulls because i cut and pasted the original insert and just switched them to nulls.

GO ILLINI
01-01-2008, 12:58 AM
almost correct
you have three fields in the first ( )'s and 4 in the second ( )'s. currently $_POST['jobname'] is going into the install_date field.

-Adam



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum