Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    Date in Database Shows 0000-00-00

    Hi Guys,
    How can i get my date to show properly in my sql database? I'm using php and have the following code.

    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.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Show us the code for your INSERT query. Tell us what data type your date column is (int, char, varchar, date, etc).

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    The field in the database is a Date field.

    Here's the insert query.

    Code:
    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
    }

  • #4
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    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
    Why not thank me?

    http://adamsworld.name

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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...
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #6
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    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?

    Code:
    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.

  • #7
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    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
    Why not thank me?

    http://adamsworld.name


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •