Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old November 21st, 2003, 12:41 AM
mdhall mdhall is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 158 mdhall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Drop down multiple select insert

I am trying to add several selections from a select menu into one field of a table. I have a list of all the U.S. States, and I want to let users select ("highlight") several states, then when the form is submitted, all of the selected states will be added together into the same field. However, no matter how I set the select area up, only the last selected state is being added to the database.

<select name="zones_pickup" size=50 multiple=yes>
<option value="Alabama"> Alabama
<option value="Alaska"> Alaska
<option value="Arizona"> Arizona
<option value="Arkansas"> Arkansas
<option value="California"> California
</select>
And so on and so on...

Any suggestions what I need to change? This goes to a php script to insert into the table, which it does with no problem, however only the last state that is selected.

Reply With Quote
  #2  
Old November 21st, 2003, 11:52 AM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Drop down multiple select insert

try setting the the select ox name up as an array like so...

<select name="zones_pickup[]" etc..

then during form processing loop through the array and create the string you want added to the db..


Reply With Quote
  #3  
Old November 21st, 2003, 12:18 PM
mdhall mdhall is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 158 mdhall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Drop down multiple select insert

I get the first par, not sure about the second (looping while inserting).

Reply With Quote
  #4  
Old November 21st, 2003, 02:12 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Drop down multiple select insert

what you need to do is loop through the array and create the string that you want to insert into the db prior to inserting it.

like so...
php Code:
Original - php Code
  1.  
  2. <?
  3. $zp=$_POST['zones_pickup'];
  4. for ($i=0; $i<count($zp); $i++){
  5. $zones = $zones.",".$zp[$i];
  6. }
  7. echo $zones;
  8.  ?>




Reply With Quote
  #5  
Old November 21st, 2003, 04:43 PM
mdhall mdhall is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 158 mdhall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Drop down multiple select insert

OK, I tried that. After the query inserts the info, it echos all of the selectins made. But all that is actually going into the table field is the word "array", not the selections.

Reply With Quote
  #6  
Old November 21st, 2003, 06:25 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Drop down multiple select insert

what variable are you using to insert the data into the DB...post the insert query...

Reply With Quote
  #7  
Old November 21st, 2003, 07:09 PM
mdhall mdhall is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 158 mdhall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Drop down multiple select insert

$sql="INSERT INTO $table_name (id,CompanyName, City, StateProvince, PostalCode,
Country, Phone, Fax, Email, TruckType, TruckLoadType, Frequency, zones_pickup) VALUES
('','$_POST[CompanyName]','$_POST[City]','$_POST[StateProvince]','$_POST[PostalCode]','$_POST[Country]','$_
POST[Phone]','$_POST[Fax]','$_POST[Email]','$_POST[TruckType]','$_POST[TruckLoadType]','$_POST[Frequency]','$_POST[zones_pickup]')";

$result=@mysql_query($sql,$connection) or die(mysql_error());

I tried changing [zones_pickup] to [zones], with no luck.

Reply With Quote
  #8  
Old November 21st, 2003, 08:18 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Drop down multiple select insert

change this...

'$_POST[zones_pickup]'

in the query to this...

'$zones'

and everything should work fine. you have to use the variable name you created in the for loop!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Drop down multiple select insert


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway