Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

Multiple comboboxes to submit one value to mysql database using php or java?

I have a very simple problem. I have a form which has 3 dropdown boxes for date of birth. I want to use separate combo boxes for the day, month and year values and then submit the product of the selection i.e 31/01/2000 to a mysql database in a table called "age" with one field in it called "age" as a DATE field.

I then want to drag/echo the information onto a page of my choice but display the echo'd result in a different format i.e. "31st of January 2000".

Can't find the answer on google so you guys are my last resort!!

Extreme thanks in advance..!

Daz

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    I recommend that you take the three inputs, for example: day, month, year and convert them into a timestamp using PHP.

    $age_timestamp = mktime(0,0,0,$month,$day,$year);

    Then record that in the SQL database. That way when you want to format the date you can do so by calling the timestamp to $age_timestamp from the SQL database, and then use the date function like so:

    date("m-d-Y", $age_timestamp);

    Doing it this way will allow you to use one field in SQL, but then gives you the versatility to format the date however you, or your audience(if you allow this option), may choose.

    Information on mktime, and date are available on the PHP site.

    Homepage: http://www.php.net/

    date: http://www.php.net/date

    mktime: http://www.php.net/mktime

    If you have any questions related to my answer, email me.

    If you have any more questions related to PHP, feel free to email me.

    Good Luck!

  • 1 decade ago

    i had a simular problem. the way I relovled this was to create a fucntion to re order the date.

    function sqlDate($x){

    if ($x!=""){

    $tmp=split("-", $x);

    return substr($tmp[2],0,2)."/".$tmp[1]."/".$tmp[0];

    }else

    return null;

    }

    that will return the date in the format of dd/mm/yyyy

    you could then try and convert this date or change the function by adding in a switch statement.

Still have questions? Get your answers by asking now.