posting a multiple select form object

Reply

Join Date: Apr 2009
Posts: 3
Reputation: jda318 is an unknown quantity at this point 
Solved Threads: 0
jda318 jda318 is offline Offline
Newbie Poster

posting a multiple select form object

 
0
  #1
Apr 16th, 2009
I have a form that I am trying to post to a table, everything works fine except for the one multiple select option I have. When it posts to the table, only the last selected option shows. How do I get it to either a. post to separate fields in the table or b. post to the same field separated by a delimiter??
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: posting a multiple select form object

 
0
  #2
Apr 16th, 2009
Can you please explain it.
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: jda318 is an unknown quantity at this point 
Solved Threads: 0
jda318 jda318 is offline Offline
Newbie Poster

Re: posting a multiple select form object

 
0
  #3
Apr 16th, 2009
Originally Posted by vicky_rawat View Post
Can you please explain it.
This is the code for the form input:
  1. <select name="grades" size="5" multiple id="grades">
  2. <option value="Pre K">Pre K</option>
  3. <option value="Kindergarten">Kindergarten</option>
  4. <option value="1st">1st</option>
  5. <option value="2nd">2nd</option>
  6. <option value="3th">3rd</option>
  7. <option value="4th">4th</option>
  8. <option value="5th">5th</option>
  9. <option value="6th">6th</option>
  10. <option value="7th">7th</option>
  11. <option value="8th">8th</option>
  12. <option value="9th">9th</option>
  13. <option value="10th">10th</option>
  14. <option value="11th">11th</option>
  15. <option value="12th">12th</option>
  16. </select>
Since there is an option to select multiple answers, I would like for all of the answers to be recorded in the database however, the only answer it posts it the last of the group. for example say 6th, 7th, and 8th were all selected. When the form is submitted, only "8th" gets posted to the correct field. Does that make sense?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: posting a multiple select form object

 
0
  #4
Apr 17th, 2009
Originally Posted by jda318 View Post
This is the code for the form input:
  1. <select name="grades" size="5" multiple id="grades">
  2. <option value="Pre K">Pre K</option>
  3. <option value="Kindergarten">Kindergarten</option>
  4. <option value="1st">1st</option>
  5. <option value="2nd">2nd</option>
  6. <option value="3th">3rd</option>
  7. <option value="4th">4th</option>
  8. <option value="5th">5th</option>
  9. <option value="6th">6th</option>
  10. <option value="7th">7th</option>
  11. <option value="8th">8th</option>
  12. <option value="9th">9th</option>
  13. <option value="10th">10th</option>
  14. <option value="11th">11th</option>
  15. <option value="12th">12th</option>
  16. </select>
Since there is an option to select multiple answers, I would like for all of the answers to be recorded in the database however, the only answer it posts it the last of the group. for example say 6th, 7th, and 8th were all selected. When the form is submitted, only "8th" gets posted to the correct field. Does that make sense?
Use array. Ie.,
  1. <select name="grades[]" size="5" multiple id="grades">
Then, as usual, use foreach($_POST['grades'] as $value) to get each of the selected value.
Last edited by peter_budo; Apr 18th, 2009 at 4:51 am. Reason: Correcting closing tag
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: posting a multiple select form object

 
0
  #5
Apr 17th, 2009
for each is the best option in this case
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: jda318 is an unknown quantity at this point 
Solved Threads: 0
jda318 jda318 is offline Offline
Newbie Poster

Re: posting a multiple select form object

 
0
  #6
Apr 17th, 2009
I tried, now instead of giving me back the last grade selected, it just prints "array". I tried to implode but it still posts the same thing!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: posting a multiple select form object

 
0
  #7
Apr 18th, 2009
Hi,

Use the following code.

  1. <?
  2. $selectedGrades=$_POST['grades'];
  3. foreach ($selectedGrades as $item)
  4. echo $item."<br>\n";
  5. ?>
  6.  
  7. <form name=frm action="" method="post">
  8. <select name="grades[]" size="5" multiple id="grades[]">
  9. <option value="Pre K">Pre K</option>
  10. <option value="Kindergarten">Kindergarten</option>
  11. <option value="1st">1st</option>
  12. <option value="2nd">2nd</option>
  13. <option value="3th">3rd</option>
  14. <option value="4th">4th</option>
  15. <option value="5th">5th</option>
  16. <option value="6th">6th</option>
  17. <option value="7th">7th</option>
  18. <option value="8th">8th</option>
  19. <option value="9th">9th</option>
  20. <option value="10th">10th</option>
  21. <option value="11th">11th</option>
  22. <option value="12th">12th</option>
  23. </select>
  24.  
  25. <input type=submit value=submit>
  26. </form>
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 3
Reputation: GameGape.com is an unknown quantity at this point 
Solved Threads: 1
GameGape.com's Avatar
GameGape.com GameGape.com is offline Offline
Newbie Poster

Re: posting a multiple select form object

 
0
  #8
Apr 18th, 2009
use foreach($_POST['grades'] as $value) to get each of the selected value.
WWW.GAMEGAPE.COM
More games, more gapes

GameGape is the premier social gaming network where people can chat, make friends, write blogs, play games and save their high scores. With a showcase of hundreds of free online games, GameGape is regarded for its high-quality games suitable for the entire family.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC