0

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??

5
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by GameGape.com
0

Can you please explain it.

This is the code for the form input:

<select name="grades" size="5" multiple id="grades">
                          <option  value="Pre K">Pre K</option>
                          <option  value="Kindergarten">Kindergarten</option>
                          <option  value="1st">1st</option>
                          <option  value="2nd">2nd</option>
                          <option  value="3th">3rd</option>
                          <option  value="4th">4th</option>
                          <option  value="5th">5th</option>
                          <option  value="6th">6th</option>
                          <option  value="7th">7th</option>
                          <option  value="8th">8th</option>
                          <option  value="9th">9th</option>
                          <option  value="10th">10th</option>
                          <option  value="11th">11th</option>
                          <option  value="12th">12th</option>
                        </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?

0

This is the code for the form input:

<select name="grades" size="5" multiple id="grades">
                          <option  value="Pre K">Pre K</option>
                          <option  value="Kindergarten">Kindergarten</option>
                          <option  value="1st">1st</option>
                          <option  value="2nd">2nd</option>
                          <option  value="3th">3rd</option>
                          <option  value="4th">4th</option>
                          <option  value="5th">5th</option>
                          <option  value="6th">6th</option>
                          <option  value="7th">7th</option>
                          <option  value="8th">8th</option>
                          <option  value="9th">9th</option>
                          <option  value="10th">10th</option>
                          <option  value="11th">11th</option>
                          <option  value="12th">12th</option>
                        </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.,

<select name="grades[]" size="5" multiple id="grades">

Then, as usual, use foreach($_POST['grades'] as $value) to get each of the selected value.

0

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!

0

Hi,

Use the following code.

<?
 $selectedGrades=$_POST['grades']; 
foreach ($selectedGrades as $item) 
echo $item."<br>\n";
?>

<form name=frm action="" method="post">
<select name="grades[]" size="5" multiple id="grades[]">
                          <option  value="Pre K">Pre K</option>
                          <option  value="Kindergarten">Kindergarten</option>
                          <option  value="1st">1st</option>
                          <option  value="2nd">2nd</option>
                          <option  value="3th">3rd</option>
                          <option  value="4th">4th</option>
                          <option  value="5th">5th</option>
                          <option  value="6th">6th</option>
                          <option  value="7th">7th</option>
                          <option  value="8th">8th</option>
                          <option  value="9th">9th</option>
                          <option  value="10th">10th</option>
                          <option  value="11th">11th</option>
                          <option  value="12th">12th</option>
                        </select>

<input type=submit value=submit>
</form>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.