Would like to convert information captured from a from to MySQL database.

I have a table with a field called "birthday" set to the date, data type.  

I have a form which collects the following:

$month = $_POST["month"];
$day = $_POST["day"]; 
$year = $_POST["year"];	

Open in new window


the format for each is as follows:

Month:
    <option value="01">January</option>, etc.

Day (single digit values for $x are 1, 2, 3, (not 01, 02, 03) etc:
<select name="day" id="day"> <?php 
 for ($x=1; $x<=31; $x++) {
 echo "<option value='$x'>$x</option>";
 }
 ?>
</select>

Open in new window



<input name ="year" value = "1980" type="text">

Open in new window

   
How to write an effective query?

i tried strtotime ("$month $day $year")

but that didn't work.

Thanks.
LVL 1
LB1234Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
What are you trying to do?
Take the selected values in the dropdown and save them in the MySQL table?
0
LB1234Author Commented:
These values are from different means, but i've already got the values in the variables listed below.  I need to know how to get the variable's values into a format MySQL will accept, and the syntax of the function i need.

$month = $_POST["month"];
$day = $_POST["day"]; 
$year = $_POST["year"];	

Open in new window

0
Marco GasiFreelancerCommented:
I didn't test it but this should work:

$d =$year . '-' . $month . '-' . str_pad($day, 2, '0', STR_PAD_LEFT);
 

Open in new window


Then use $d in your query.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Ray PaseurCommented:
Please take a moment to read this article.  It will save you a ton of work once you know how PHP handles this DATE/TIME stuff.  Pay particular attention to the ISO-8601 format for datetime values.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Next, take a moment to experiment with form input using free-form dates.  You'll quickly conclude that there is no need for elaborate input controls -- just use the PHP tools and your clients will love you for it!.
http://iconoun.com/demo/strtotime.php
0
Ray PaseurCommented:
Let's assume that these variables have been filtered and you're satisfied with the contents (they represent integers in the acceptable ranges for the date).

$month = $_POST["month"];
$day = $_POST["day"]; 
$year = $_POST["year"];	
$isodate = date('c', strtotime("$year-$month-$day"));
print_r($isodate);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LB1234Author Commented:
Awesome Ray!  Thanks. Question though...

My table is listed below; please note the number format.  Your code outputs the following : 2000-10-01T00:00:00+02:00

Will that be an issue?

table desc
0
LB1234Author Commented:
Thanks Ray!
0
Ray PaseurCommented:
That should not be an issue if the birthday column is defined as DATE or DATETIME.  MySQL leans toward silent truncation of data elements that exceed the width of the column.

Thanks for the points and best of luck with your project, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.