Forum Moderators: coopster

Message Too Old, No Replies

php update multiple mysql rows using checkboxes

         

bizkit1

8:05 pm on Feb 23, 2010 (gmt 0)

10+ Year Member



Hello everybody.
i made a script that reads from a database and displays users that have "status" row set to 1. The other users that have 0 aren`t displayed. For me to activate every user i have to select one by one and modify status from 0 to 1. I was wondering how can i make in php two checkboxes, one with value 0 and the other with value 1, and by checking multiple checkboxes i can activate/deactivate multiple users.

Thank you in advance

Zipper

8:40 pm on Feb 23, 2010 (gmt 0)

10+ Year Member



If you want a user to only select one option (active or inactive) the best approach is to use radio buttons instead of check boxes. Just make sure their name is the same. For an example.

<input type="radio" name="active" value="1"> Active 
<input type="radio" name="active" value="0"> Inactive


And using a submit button or the onclick event for the radio buttons you can call your php script to update the corresponding status in the database.

bizkit1

8:45 pm on Feb 23, 2010 (gmt 0)

10+ Year Member



that`s the problem...i don`t know how to make this php script. I read some threads but it`s too complicated for me.

Readie

3:13 am on Feb 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it's quite simple really, you grab the value of (to use Zipper's HTML) "active" and update it into the database:

$active = $_POST['active'];
if(isset($active) && $active != "") {
// MySQL update query
}