Tutorials

Working with checkboxes and a database

by Ben Smithers on Jan 10, 2009 12:47:52 PM

Introduction

Over in the php help forum, the question of how to deal with checkboxes arises pretty often. Usually, people want to be able to select which rows of a database to update/delete/throw out the window.

The concept is actually pretty simple. It involves naming your checkbox as an array and the use of the IN mysql clause. This tutorial aims to give a simple example in the hope that, next time someone asks, I can point them to a tutorial rather than explaining all over again.

Right, on with the show.

Comments

Needed to modify this variable to check the admin box if they were already admins...
$checked = ($admin==1) ? 'checked' : '';
Awesome tutorial man, learned alot, thank you very much...

1. savagenoob on Mar 1, 2009 8:34:25 PM

is there a demo anywhere of this?

2. acctman on Mar 10, 2009 7:05:57 PM

acctman, i could probably put this up somewhere, but im not sure what the point would be. What exactly did you want a demo of? There's not a lot of see apart from a few text boxes. The meat of the tutorial is the php code.

3. Ben Smithers on Mar 11, 2009 4:00:25 AM

Here are some source files that could help

http://diadde.com/dl/mail.zip

a clay
http://hubpages.com/profile/Alpho011

4. Alpho011 on Apr 1, 2009 2:06:53 PM

thanks! i realy need that!

5. aviavi on Apr 15, 2009 4:25:07 PM

Awesome, learned some new functions from this tutorial, thanks! :) Great tutorial by the way.

6. xnowandtheworldx on May 2, 2009 1:17:02 AM

Super! I added a second row of checkboxes and had some problems when no checkbox is ticked in one of both colums. But finaly, I simply droppt the OR command after the mysql_query(UPDATE ...) and so it works!
I learned a lot- thank you!

7. Paprikate on Jun 24, 2009 9:56:45 AM
Login or register to post a comment.