1.

Solve : PHP - how to send/receive multiple select boxes??

Answer» HEY guys,

I'm in NEED of URGENT PHP help.

I have a table displaying hockey players from a database (no fixed number of players) and the last column allows the user to change/update player's status. There are three choices in each select box, the user can select only one for each player displayed in the table.

I added a hidden field with player's id to know who to update, I'm stuck as to how to setup select boxes. Will they all have the same name? is there some kind of array I should be using? How do I receive this data on another page to process and update the database.

Thanks to all in advance.

ultimatum.Nvm, just figured it out.

For those interested here is how you set it up:

Hidden field:
Code: [Select]<input type='hidden' name='playerId[]' value='someValue' />
Select boxes:
Code: [Select]<select name='rStatus[]'>
<option value='xyz'>xyz</option>
<option value='xyz'>xyz</option>
<option value='xyz'>xyz</option>
<option value='xyz'>xyz</option></td>
</select>
This is just to check if SELECT BOXes work because actual processing is a little different but you can use your imagination:
Code: [Select]foreach($_POST['rStatus'] as $new_status)
{
//$query = "UPDATE players SET status= '$new_status' WHERE id = $new_id";
echo $new_status."<br />";
}
Same applies to the hidden values, just change the name in $_POST['here'] area.

Cheers.
Thanks for posting the code.

You may want to htmlentities() and strip_tags() before adding to the database THOUGH, to prevent XSS.Very good point. I excluded that mainly because the project is kind of small (20 users) and log-in to the page is already secure.

Thanks for the tip kpac.


Discussion

No Comment Found