insert query wont insert date using drop down list

Discussion in 'PHP' started by macaela, Sep 24, 2010.

  1. #1
    I have have a drop down list which meant to insert date of birth into database cloumn name date_of_birth bt is not wrking it inserts all the data except tha column help what am doing wrong????

    $date_of_birth = $_POST['year_of_birth'] . '-' . $_POST['month_of_birth'] . '-' . $_POST['day_of_birth'];
    
    $q = "INSERT INTO driversnew (id, name, location, date_of_birth, car_number,
    
       favourite_track, least_favourite_track, achievements, sponsors, email, image, display)
    
    VALUES ('$_POST[id]', '$_POST[name]', '$_POST[location]','$date_of_birth','$_POST[car_number]','$_POST[favourite_track]', '$_POST[least_favourite_track]','$_POST[achievements]', '$_POST[sponsors]','$_POST[email]', '$image_name','0')";
    
    $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); 
    
    PHP:
    this the form
    
    <?php
    
    $months = array('','January','February','March','April','May','June','July','August','September','October','November','December');
    
    echo '<select name="month_of_birth">';
    
    for ($i=1;$i<13;++$i) {
    
       echo '<option value="' . sprintf("%02d",$i) . '">' . $months[$i] . '</option>';
    
    }
    
    echo '</select>';
    
    echo '<select name="day_of_birth">';
    
    for ($i=1;$i<32;++$i) {
    
       echo '<option value="' . sprintf("%02d",$i) . '">' . $i . '</option>';
    
    }
    
    echo '</select>';
    
    echo '<select name="year_of_birth">';
    
    $year = date("Y");
    
    for ($i = $year;$i > $year-50;$i--) {
    
       $s = ($i == $year)?' selected':'';
    
       echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>';
    
    }
    
    echo '</select>';
    
    ?>
    
    
    PHP:

     
    macaela, Sep 24, 2010 IP
  2. systemick

    systemick Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You don't say what format the date_of_birth column is in. Is it date/datetime or unix timestamp. I suspect that the format of the date that you are attempting to insert is wrong
     
    systemick, Sep 25, 2010 IP
  3. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #3
    date_of_birth is this date field or datetime field in database ?

    u can see date /datetime row insertion like this INSERT INTO test (`date` ,`datetime`) VALUES ('2010-09-08', '2010-09-10 17:12:10');
     
    chandan123, Sep 25, 2010 IP
  4. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    hi i manage to get the insert date to work bt now the problems is how to keep the value of the drop dwon lists i know how to keep am input but how do i keep for the options list??

    $months = array('','January','February','March','April','May','June','July','August','September','October','November','December');
    
    echo '<select name="month_of_birth">';
    
    for ($i=1;$i<13;++$i) {
    
       echo '<option value="' . sprintf("%02d",$i) . '">' . $months[$i] . '</option>';
    
    }
    
    echo '</select>';
    
    echo '<select name="day_of_birth">';
    
    for ($i=1;$i<32;++$i) {
    
       echo '<option value="' . sprintf("%02d",$i) . '">' . $i . '</option>';
    
    }
    
    echo '</select>';
    
    echo '<select name="year_of_birth">';
    
    $year = date("Y");
    
    for ($i = $year;$i > $year-50;$i--) {
    
       $s = ($i == $year)?' selected':'';
    
       echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>';
    
    }
    
    echo '</select>';
    PHP:
     
    macaela, Sep 25, 2010 IP