Current location: Hot Scripts Forums » Programming Languages » PHP » Multiple form fields saved in one mysql field??


Multiple form fields saved in one mysql field??

Reply
  #1 (permalink)  
Old 10-14-04, 01:50 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Multiple form fields saved in one mysql field??

This maybe an elementary question to post in this forum, but I am stumped and need a bit of help (I am a newbie to php). I have 3 drop down fields in a form. Each drop down list is the same list of cities. I would first of all want to know how to go about saving the 3 fields as a comma seperated list in one mysql field. I am guessing that I cannot with just simple html since it would require a separate field in the mysql for each name ...and if I name them the same field name, probably only one would get listed in the mysql field. I think it will require php to merge them together.

Example...
<select size="1" name="City1">
<option>Atlanta</option>
<option>Athens</option>
<option>Rome</option>
<option>Thomasville</option>
</select>

<select size="1" name="City2">
<option>Atlanta</option>
<option>Athens</option>
<option>Rome</option>
<option>Thomasville</option>
</select>

Saved under Mysql Field 'city' as
"Athens,Rome"
instead of having to save as mysql field 'city1' = 'Athens' & 'city2' = 'Rome'

Any IDEAS?
Chris Chandler
Quoting Loans
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-14-04, 02:32 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

#to insert

// open db connection
$city = array($_POST['city1'], $_POST['city2'], $_POST['city3']);
$commaseparated implode(','$city);
mysql_query("insert into table set citys='$commaseparated'") or die('error: '.mysql_error());

# use
// open db
// fetch result
$citys explode(','$resultcityvar); 
hope it helps
Wille
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-14-04, 02:43 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
ok thanks. I will try that.

Last edited by cebuy; 10-14-04 at 02:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-14-04, 03:35 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
oh.. forgot to mention.. when you do what ever you do with the citys (echo etc.) the usage will be like this:
PHP Code:

# use 

// open db 
// fetch result 
$citys explode(','$resultcityvar);

echo 
$citys[0]; // outputs city1 value
echo $citys[1]; // outputs city2 value 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-15-04, 01:08 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
ok, great! that is helping tremendously.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with updating a multiple checkbox form to a MySQL DB jimb575 PHP 1 01-31-06 09:04 PM
formmail problem gscraper Perl 12 08-27-04 04:06 AM
transfer multiple value of a form field to another field ore JavaScript 2 06-18-04 09:50 PM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 11:15 AM
Formmail Script Fix - Cant display multiple list selections.. zamen PHP 3 05-02-04 10:59 AM


All times are GMT -5. The time now is 09:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.