Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Storing Checkbox Data In Your Database
We'll have a user table that contains user login information such as username, password, and some other fields that we might use. A simple user table is shown below. I will assume you can create a table like this if you plan to use some of the example code found later in the article.
id username
1 User1
2 User2
3 User3
We first create a table called "const_skills" with the following SQL code:
SQL> CREATE TABLE const_skills ( 
	id     int  not null primary key, 	 
	value  varchar(20) );
And now we will populate it with skills:
SQL> INSERT INTO const_skills(id, value) VALUES (1, "PHP");
SQL> INSERT INTO const_skills(id, value) VALUES (2, "MySQL");
SQL> INSERT INTO const_skills(id, value) VALUES (3, "Zope");
SQL> INSERT INTO const_skills(id, value) VALUES (4, "Perl");
SQL> INSERT INTO const_skills(id, value) VALUES (5, "Javascript");
SQL> INSERT INTO const_skills(id, value) VALUES (6, "JSP");
Your const_skills table now looks like this:
id value
1 PHP
2 MySQL
3 Zope
4 Perl
5 Javascript
6 JSP
This table's only purpose is to hold the names of the skills that web developers can select. Now, create a table called "lookup_skills" with the following SQL:
SQL> CREATE TABLE lookup_skills ( 
	id        int  not null auto_increment primary key,
	uid       int,
	skill_id  int );
The purpose of lookup_skills is to provide a mapping from userids to web devloper skills. In other words, it allows us to store the developers and what skills they have. So, when the unemployed web developer hits the submit button after filling out our form, we will populate this table with the checkbox values that were checked off. For each skill the developer checks off, a row will be added with the user's uid from the user table and the number corresponding to the skill he selected in the const_skills table. Before we look at the code to do the insert, lets first use our design to make creating our form easier. Each time that the user requests the page that has our form on it, we can query the database and get the checkbox labels from the const_skills table and create the checkbox form with the appropriate checkbox choices. Here is the code to do that.
[ Next Page ]

[Page 1]  [Page 2]  


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.