PDA

View Full Version : inserting 3 fields into 1


loonatik
04-25-2003, 11:26 PM
My submission form asks for a person's birthdate:

<select name='month'>....</select>
<select name='day'>....</select>
<input type='text' name='year'>

In the db, there is one field called "birthdate". I want to insert the month, day, and year in the form "00-00-0000" into that one field in the db. Right now I have mysql_query ("INSERT INTO members (name,email,username,password,birthdate) values ('".$_POST[name]."','".$_POST[email]."','".$_POST[username]."','".$_POST[password]."',''".$_POST[birthdate]."", $dbh);

I tried passing
<input type='hidden' name='birthdate' value='".$month."".$day."".$year."'>
in the form, but it doesnt work. Any solution? Thanks.

raf
04-26-2003, 10:59 AM
This is not a MySQL question, but a PHP one ;)

Anyway, you just need to build the value in PHP and then insert that in the sql-string
something like
$birthdate= $_POST[month] . "-" . $_POST[day] . "-" . $_POST[year]
end then
("INSERT INTO members (name,email,username,password,birthdate) values ('".$_POST[name]."','".$_POST[email]."','".$_POST[username]."','".$_POST[password]."',''' . $birthdate . "'");

I suppose it is a textfield (MySQL stores a Y-M-D) and removed the last variable since there were more values then variables in your statement

You need to check for the year to see if it is a numeric field with four characters. Frankly, i would also use a dropdown there (to preserve uniformity with the month and day. You can build it dynamically using a loop that begins at the current year and loops till 1920 or whatever.