By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,319 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

Combining multiple form items to one DB field

P: n/a
Is there a way to combine the values of multiple form items such as two
textboxes and one radio button for insertion into one MYSQL database
field?

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Just use the dot operator to join the fields, i.e.

$combined = $_POST['textfield_1'] . $_POST['textfield_2'] .
$_POST['radio_button'];

that way you can use $combined to insert into MySql attribute. Hope
this helps.

Jul 17 '05 #2

P: n/a
perplexed wrote:
Is there a way to combine the values of multiple form items such as two
textboxes and one radio button for insertion into one MYSQL database
field?


I think you would do better by revising your database structure.

Anyway, try this (unchecked and missing validation):

$combined = '';
$combined .= serialize($_POST['text1']);
$combined .= serialize($_POST['text2']);
$combined .= serialize($_POST['radio']);
/* write $combined to a DB text column */
And reading it back in:

$combined = 's:5:"text1";s:5:"text2";b:1;';
/* last value was read from the DB */
$values = explode(';', $combined);
$text1 = unserialize($values[0]);
$text2 = unserialize($values[1]);
$radio = unserialize($values[2]);

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.