i want help plz

Discussion in 'PHP' started by mirosoft1, Jan 14, 2008.

  1. #1
    i have a field on database with mysql called birthdate i divided it into 3 fields
    year
    month
    day
    because on the form i put a comobo box to the year and combo box to day and other to month and put every value on field but
    i want to but from this three combobox on one field called birthdate
    how i can do that
    please help me
    thank you
     
    mirosoft1, Jan 14, 2008 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    OK, so say you have the three combo boxes, retrieve a value from each of them:

    Example HTML:

    
    <select name='day'>Options<select>
    <select name='month'>Options<select>
    <select name='year'>Options<select>
    
    Code (markup):
    PHP
    
    //Declare the variables
    $day = $_POST['day'];
    $month = $_POST['month'];
    $year = $_POST['year'];
    
    //Create an array
    $dateparts = array($month,$day,$year);
    
    $date = implode("-",$dateparts);
    
    
    PHP:
    Then $date is equal to month-day-year, which if I am not mistaken is the same syntax as MySQL DATE.

    BP
     
    blueparukia, Jan 14, 2008 IP
    triphp123 likes this.
  3. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #3
    I believe the code above works but why use so many variables? It can be as simple as this:

    
    $date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
    
    PHP:
     
    rkquest, Jan 14, 2008 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    I always like to keep $_POST['variables'] as $variables, in case I need to use them later, and don't wish to retype $_POST['variables'] every time.

    And I used implode cause I've never had a reason to use it before :p
     
    blueparukia, Jan 14, 2008 IP
  5. mirosoft1

    mirosoft1 Well-Known Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    yes the two codes are very good and work
    thank you very much
     
    mirosoft1, Jan 15, 2008 IP
  6. cr0cx

    cr0cx Active Member

    Messages:
    149
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #6
    cuz remember sql uses a YYYY-MM-DD format..
     
    cr0cx, Jan 15, 2008 IP
  7. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #7
    :confused: I thought is was MM-DD-YYY. Anyway my code is easily editable like that
     
    blueparukia, Jan 15, 2008 IP