Page 1 of 1
how to save multiple text/combo box to 1 mysql field
Posted: Tue Oct 14, 2008 12:07 pm
by ecxzqute
hey guys ang php gurus out there..
i'm new in php programming and i have this little question in my mind,
is it possible to save multiple combo/text box values into a single field in my mysql database?
because i have this 1 combo box and two text fields that gets the values of birthdate information from a user.
if this is possible, can anyone who knows this kindly help me please?
thanks in advance
ecx..
Re: how to save multiple text/combo box to 1 mysql field
Posted: Tue Oct 14, 2008 12:46 pm
by califdon
Please be more specific. What is the field in your database? Is it a date field? What are the 3 Form fields, perhaps Month, Day and Year? Which one is a combo box?
Re: how to save multiple text/combo box to 1 mysql field
Posted: Wed Oct 15, 2008 5:06 am
by ecxzqute
yes sir califdon, ur definitely right,
i have these form fields day, month and year and i want it
to be saved in my field "b_day" in my database.
how can i do this?
Re: how to save multiple text/combo box to 1 mysql field
Posted: Wed Oct 15, 2008 5:21 am
by Kadanis
On the form submission just concatenate the 3 field data sets before posting to the database.
For example
Code: Select all
<?php
//check form submisson
if (count($_POST) > 0){
//get form variables
$day = (isset($_POST['day'])) ? $_POST['day'] : '';
$month= (isset($_POST['month'])) ? $_POST['month'] : '';
$year= (isset($_POST['year'])) ? $_POST['year'] : '';
//insert validation on the values sent from the form
//you should be expecting a 2 digit day value, a 2 digit month value and a 4 digit year value
//concatenate string (i've put in in the order yyyy-mm-dd for mysql)
$fullDate = $year . '-' . $month . '-' . $day;
//build sql statement
$sql = "INSERT INTO `table` SET `dateField` = '".$fullDate."' WHERE `pk` = 'x';";
}
?>