how to save multiple text/combo box to 1 mysql field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ecxzqute
Forum Commoner
Posts: 29
Joined: Tue Oct 14, 2008 12:26 am

how to save multiple text/combo box to 1 mysql field

Post 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..
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how to save multiple text/combo box to 1 mysql field

Post 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?
ecxzqute
Forum Commoner
Posts: 29
Joined: Tue Oct 14, 2008 12:26 am

Re: how to save multiple text/combo box to 1 mysql field

Post 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?
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Re: how to save multiple text/combo box to 1 mysql field

Post 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';";
}
?>
 
Post Reply