views:

161

answers:

2

Hello,

I have a form which asks the user his or her date of birth. Its a drop down box since I use the select input type. The first drop down has Months, second has Days, the third has the Years. So the format should be Month(October), Day(25), Year(1990). In other words the months spell out the actual month and not simply the number representation of the month. However, I would like to save the Day and Year in their respective formats. How can I do this in phpMyAdmin? Should I use the DATE type? what should the value be? I just need to know how to correlate all of this in phpmyadmin, so I can save it properly. Thank you.

+1  A: 

Should I use the DATE type?

Yes and here is how you can concatenate them and store in the database:

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

$date = $month . '-' . $day . '-' . $year;

Now you can use the $date variable in your query against the date type field.

Sarfraz
Yep, both answers worked great! Thank you all.
Newbie_25
+1  A: 

Not phpmyAdmin but mysql you mean I hope.

Well, you have to distinguish the value of the thing and it's representation.
While value can be always the same, representation may vary.

The only way to store date in MySQL is to store it in the date field, which has strict format:

YYYY-MM-DD

And you have to store your date in this format only. To do this, you have to make your month select like this:

<select name="month">
  <option value="1">January</option>
  <option value="2">February</option>
  ...
</select>

So, month will be represented with word, while numeric value will be sent to the server.
Now, along with day and year variables, you can assemble a date string:

$date = $_POST['year']."-". $_POST['month']."-".$_POST['day'];
$date = mysql_real_escape_string($date);

Now you have your date ready to store in the database.

Col. Shrapnel