Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

mysql handling Date of Births

  • 17-01-2009 06:55PM
    #1
    Registered Users, Registered Users 2 Posts: 3,875 ✭✭✭


    Hello,
    whats is the best way of entering a date of birth from a form into a mysql database

    I would like to use three combo boxes as in day month and year,
    but I do not know how to input the results of all three boxes into mysql and also how to validate this,

    does anyone have any ideas,

    or even just how to validate a text field in the dd-mm-yyyy format

    cheers.


Comments

  • Moderators, Education Moderators, Home & Garden Moderators Posts: 8,313 Mod ✭✭✭✭Jonathan


    This for school/college?


  • Registered Users, Registered Users 2 Posts: 3,875 ✭✭✭ShoulderChip


    its for a database website I am building for a friend, I am just realising I may not even need to do it this way I could just have the three combo boxes as I dont have a need for calculating age

    my one question then would be how can I allow the year field to start on todays year and go back 100 hundred years?
    that way it would be future proof.


  • Moderators, Education Moderators, Home & Garden Moderators Posts: 8,313 Mod ✭✭✭✭Jonathan


    Sounds to me like you are talking about php rather than sql.


  • Registered Users, Registered Users 2 Posts: 8,488 ✭✭✭Goodshape


    Actually working on something similar this very minute.

    Here's what works for me, maybe you can use it or adapt it.

    [php]

    $day = $_GET["day"];
    $month = $_GET["month"];
    $year = $_GET["year"];
    $hour = $_GET["hour"];
    $minute = $_GET["minute"];

    $values = "$year-$month-$day $hour:$minute:00";
    [/php]

    That final $values is ready to be put into MySQL. That's the format used.


  • Registered Users, Registered Users 2 Posts: 3,875 ✭✭✭ShoulderChip


    cheers thanks for that

    I am having one other very short problem

    I am displaying a table of records, yet i want the user to have the option to filter it

    so i have set up a combo list to decide what they want to filter it on (job title etc)

    I then have a submit button which submits the form
    i then have a second submit button which links to the second page with the result of the combo box attached as an form parameter

    My problem is it only works if i click submit 1 and then submit 2 i have tried everything to get a single submit button to post the form and then link to the page with the form parameter but with no link


  • Advertisement
  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    for outputting the year selector:

    [php]
    <?

    $current_year=date('Y');
    $earliest_year=$current_year-101;

    for($year=$current_year; $year>$earliest_year; $year--) {
    $options.="<option value='$year'>$year</option>";
    }

    ?>

    <select>
    <?= $options; ?>
    </select>
    [/php]


  • Registered Users, Registered Users 2 Posts: 3,875 ✭✭✭ShoulderChip


    Edit I figured out the two submit buttons.
    cheers.


Advertisement