943,699 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1776
  • PHP RSS
Apr 16th, 2009
0

posting a multiple select form object

Expand Post »
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??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jda318 is offline Offline
3 posts
since Apr 2009
Apr 16th, 2009
0

Re: posting a multiple select form object

Can you please explain it.
Reputation Points: 28
Solved Threads: 19
Junior Poster
vicky_rawat is offline Offline
137 posts
since Jun 2008
Apr 16th, 2009
0

Re: posting a multiple select form object

Can you please explain it.
This is the code for the form input:
PHP Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jda318 is offline Offline
3 posts
since Apr 2009
Apr 17th, 2009
0

Re: posting a multiple select form object

Click to Expand / Collapse  Quote originally posted by jda318 ...
This is the code for the form input:
PHP Syntax (Toggle Plain Text)
  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.,
html Syntax (Toggle Plain Text)
  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
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Apr 17th, 2009
0

Re: posting a multiple select form object

for each is the best option in this case
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 17th, 2009
0

Re: posting a multiple select form object

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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jda318 is offline Offline
3 posts
since Apr 2009
Apr 18th, 2009
0

Re: posting a multiple select form object

Hi,

Use the following code.

PHP Syntax (Toggle Plain Text)
  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>
Reputation Points: 28
Solved Threads: 19
Junior Poster
vicky_rawat is offline Offline
137 posts
since Jun 2008
Apr 18th, 2009
0

Re: posting a multiple select form object

use foreach($_POST['grades'] as $value) to get each of the selected value.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
GameGape.com is offline Offline
3 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Parse error: syntax error, unexpected $end
Next Thread in PHP Forum Timeline: Write to a HTML page using PHP?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC