Combining multiple form items to one DB field

This is a discussion on Combining multiple form items to one DB field within the PHP Language forums, part of the PHP Programming Forums category; Is there a way to combine the values of multiple form items such as two textboxes and one radio button ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-13-2004
perplexed
 
Posts: n/a
Default Combining multiple form items to one DB field

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?

Reply With Quote
  #2 (permalink)  
Old 12-13-2004
Gerald.Yeo@gmail.com
 
Posts: n/a
Default Re: Combining multiple form items to one DB field

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.

Reply With Quote
  #3 (permalink)  
Old 12-13-2004
Pedro Graca
 
Posts: n/a
Default Re: Combining multiple form items to one DB field

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!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0