Linux System Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Storing Checkbox Data In Your Database
Introduction
Checkboxes in web forms are useful because they allow the person filling out the form to choose from a wide range of possible choices. Specifically, it allows the user to choose some, all or none of the elements. Although checkboxes are excellent form elements for certain tasks, there is often confusion about how to store checkbox data correctly. This article will demonstrate how to store checkbox data in a database, in a manner that follows good database design principles.
Requirements
In this article, I will demonstrate the method of storing checkbox data on a per user basis. Although there is useable PHP source code included, I'm presenting this in a database design point of view. Therefore, the information here can be used with any database and server side scripting language of choice. The main idea here is to provide you with an explanation of how to do it so you can apply it to the sites you build. If you do want to play with the source code, you'll need php, mysql, and a webserver.
Example: A Job Posting Site
Consider the following situation. You are asked to create a web site that will allow unemployed web developers to post their skills there. Potential employers can then visit this website and search for prospective employees, based on the skills they are looking for. As an aspiring web developer yourself, you know that a web programmer with work is more desirable than one without. Therefore, you decide to write the code for his site.
Each unemployed web developer will presumably visit the site, create an account, and enter his skills in some way or another. Checkboxes immediately come to mind. You envision a page that looks something like this:
  __ PHP     __ MySQL        __ Zope
  __ Perl    __ Javascript   __ JSP

                          [Submit]
Each developer goes through and checks the boxes that match his skills. Obviously, different developers will check different boxes. One may check PHP and MySQL, while another checks only JSP. How will you store this data? It is natural to want to store each developer's list of skills in the user table shown above. After all, each user will have a row in this table and you can just make some fields in each row to hold their skills. This may work at first, but you will almost surely run into trouble at some point when you wish to expand or modify the database. Also, your user table would be unnecessarily wide. There is a better way to do this. Here is how.
[ Next Page ]


Comments:
CheckBox - Expand/colapsedan07/16/08 04:36
Checkbox Values - sending via php mail() funcMangala Packiam12/07/07 00:41
Checkbox Values - sending via php mail() funcMegan08/08/07 14:37
Need Help on modifying record using checkboxAndy Christian Loyola08/02/07 03:51
Select all Checkbox using PHPSrikanth06/13/07 15:51
check box values are not stored in mysql DB!ramya06/08/07 05:11
checkbox: set to "checked"angie05/22/07 04:41
plz help merevathi04/23/07 07:35
not getting the datarevathi04/23/07 02:09
missing argument in make_checkbox_html()redcoder12/06/05 10:10
checkbox coding in jspchahal10/18/05 01:23
RE: How to know if checkbox is checkedCyrus10/01/05 16:30
Checkbox and PHPegoleo08/23/05 10:35
help pleaseremon07/18/05 07:46
RE: valid check boxg.g.ramkumar07/11/05 14:21
add more than one check box value using jspThamilselvi04/11/05 05:52
valid check boxJujur02/23/05 00:54
how 2 insert the data !!devien11/26/04 23:32
RE: checkbox woeskimbo08/08/04 10:21
Heres how to displayed checked boxesTerry Beyer04/24/03 15:08
genmap connection with Oracle 8iJalaluddin10/13/02 03:32
why not store checkbox values in a "set"?Eepē10/06/02 13:21
RE: How to know if checkbox is checkedminds10/04/02 16:47
How to know if checkbox is checkedJoachim09/27/02 08:27
wich value has an unchecked checkbox;Ruud Schuring09/27/02 07:47
checkbox woesEepē09/19/02 18:32
checkboxramarao09/11/02 07:23
PLEASE NOTE FOR MISSING ARGUMENTSAndy09/09/02 06:00
add checkbox values to a stringnowshaba09/08/02 04:52
RE: retrieving checkbox values, comma delimitedGunasekari09/03/02 04:21
Storing multiple checkbox data in a databasenik_crash08/30/02 02:58
Error on line 51Jeff08/19/02 00:06
Can anyone give me full code?Chris07/31/02 18:01
retrieving checkbox values, comma delimitedarif07/16/02 17:12
RE: Don't forget the [ ] in your checkbox tagelaine07/12/02 12:46
RE: Check Box functionsHeykel05/01/02 15:58
RE: checkboxHeykel05/01/02 15:52
Error in insert queryathearer04/20/02 22:39
validate formTham Siew Lai04/19/02 22:57
RE: Any suggestions about storing as a string?Dave04/10/02 22:03
RE: Coding errorBrian Razzaque04/08/02 01:32
RE: Checking/unchecking checkbox to update mysqlDan Chiasson03/28/02 09:46
Checking/unchecking checkbox to update mysqlAmy03/22/02 17:58
A Better WayBryan03/22/02 09:43
checkboxstkytreat03/15/02 18:31
Don't forget the [ ] in your checkbox tag!Jordi Lafortune03/04/02 16:28
RE: Bitflags?Davison Long02/21/02 05:26
cant get startedpax02/20/02 00:48
code in JSPBabar Malik02/18/02 06:26
RE: checkboxesBabar Malik02/18/02 06:15
a slightly different method?vocoder02/07/02 16:00
RE: A single checkboxEvan Johnson01/14/02 20:12
A single checkboxvijay12/13/01 15:39
moving this furtherCosti11/18/01 00:08
A single checkboxTim Brown11/06/01 20:26
RE: Simpler Method...Saveli K10/25/01 09:05
Working Demo?nobledeed10/09/01 12:55
RE: checkboxesAllen McGrath10/09/01 10:27
checkboxesGeorge Kosmidis10/02/01 03:35
RE: Editing the codeTed08/31/01 06:42
Editing the codeRichard08/26/01 20:45
Why don't you add my reaction?Tobias Beuving08/11/01 21:59
storing checkboxes as a string like . . .Tobias Beuving08/03/01 18:34
Any suggestions about storing as a string?Tobias Beuving07/31/01 08:08
CheckboxesDaniela07/19/01 10:04
Alternate solution to $checked array woesg0odthrust06/28/01 13:45
RE: Coding errorg0odthrust06/26/01 15:48
Error in purge function (page 4)Daniel06/14/01 06:54
RE: Bitflags?ARTHUR06/11/01 06:23
RE: Bitflags?Kristof Polleunis06/05/01 05:25
acessing html checkboxes in phpmunendra sharma04/30/01 21:45
RE: Simpler Method...Hasib04/27/01 13:47
Simpler Method...Sean04/24/01 15:09
RE: my way to use checkbox in phpJay P Narain04/14/01 14:07
RE: my way to use checkbox in phpJay P narain04/04/01 19:49
RE: Coding errorStiwi03/14/01 21:50
Function names must be strings???marlow02/20/01 10:50
how to scale db design approachEllen S.02/04/01 18:47
RE: Coding errorkiter01/19/01 02:06
RE: confuse with the article...kiter01/18/01 02:52
confuse with the article...kiter01/17/01 03:28
RE: my way to use checkbox in phpweiwu01/08/01 10:13
RE: my way to use checkbox in phpFresh Guy01/07/01 21:50
MySQL Connectiondharmu11/13/00 07:57
RE: Coding errorMohd Yusrin11/09/00 22:50
RE: Bitflags?Bryan Gregorius11/07/00 13:37
RE: Web forum with MySQLAndrew Coldham11/02/00 04:36
Web forum with MySQLNicoleta10/31/00 11:48
Re: Checkbox articleKris D10/29/00 22:25
RE: Bitflags?Jeppe Salvesen10/26/00 15:45
RE: database design [could be improved]rad10/25/00 05:38
RE: Bitflags?rad10/25/00 05:28
RE: Bitflags?Terence10/24/00 01:51
RE: Better way to store a setTerence10/24/00 01:39
Bitflags?Pilif10/23/00 11:49
RE: Better way to store a setBertrand Mansion10/23/00 05:39
better SQLKaoslord10/22/00 17:28
RE: How scalable is this method??Jeremy James10/21/00 13:46
Normalization and IndexingMichael Brown10/20/00 16:54
RE: Website performance vs. ease of changesLee Lemon10/19/00 15:11
How scalable is this method??Jason Cox10/19/00 12:56
my way to use checkbox in phpweiwu10/19/00 11:48
Website performance vs. ease of changesFrank Seesink10/19/00 02:25
RE: Better way to store a setscott10/18/00 11:56
RE: Better way to store a setTim Perdue, PHPBuilder.com10/18/00 10:27
Better way to store a setDavid Phillips10/17/00 23:14
RE: Comment SuggestionCymen10/17/00 16:01
Comment SuggestionBob Cobb10/17/00 07:32
Implode(), implode()...Maxim Maletsky10/17/00 01:02
database design [could be improved]Terence10/16/00 22:24
RE: SET column type.Chris Kings-Lynne10/16/00 21:50
A cleaner approach sometimes...?Chuck Shunk10/16/00 14:10
SET column type.Richard Heyes10/16/00 09:35
Coding errorMike M10/16/00 09:16
That wasn't so badmorpheus10/16/00 07:27
Check Box articleNilanjan Chaks10/16/00 00:50
Check Box functionsNilanjan Chaks10/16/00 00:18
remove the final ORKirk Parker10/15/00 23:14
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.