Hi all, I was looking to use check boxes in a html form for a registration page.
HTML Code:
<input type="checkbox" name="Industry" value="Ecommerce" /></input><label for="Ecommerce">Ecommerce</label>
<input type="checkbox" name="Industry" value="IT - Web Design" /></input><label for="IT - Web Design">IT - Web Design</label>
PHP Code
$insert = mysql_query("insert into $table values ('NUll',
'".$_POST['CompanyName']."',
'".$_POST['Address']."',
'".$_POST['Town']."',
'".$_POST['PostCode']."',
'".$_POST['Telephone']."',
'".$_POST['Fax']."',
'".$_POST['Url']."',
'".$_POST['Email']."',
'".$_POST['Industry']."',
'".$_POST['Description']."')")
or die ("Could not insert ".mysql_error());
the mysql all i see is "array".
Any help would be great
many thanks
James
PHP Check boxes
Moderator: General Moderators
Re: PHP Check boxes
I think you need a radio buttons instead of check boxes ...
There are 10 types of people in this world, those who understand binary and those who don't
Re: PHP Check boxes
I spent all that time writing this tutorial and noone reads it 
-
webtech123
- Forum Newbie
- Posts: 2
- Joined: Fri Jan 18, 2008 8:32 am
Re: PHP Check boxes
Thanks for your reply. What if i wanted multiple answers? The checkboxes are to register your industry interest(s), some have more than one.
James
James
Re: PHP Check boxes
Then you'll have to normalize your tables.
Read this http://www.devshed.com/c/a/MySQL/An-Int ... alization/
Read this http://www.devshed.com/c/a/MySQL/An-Int ... alization/
There are 10 types of people in this world, those who understand binary and those who don't
-
thinsoldier
- Forum Contributor
- Posts: 367
- Joined: Fri Jul 20, 2007 11:29 am
- Contact:
Re: PHP Check boxes
Always a good thing to do but for quick and simple projects you can get away with just saving a comma separated string to a text field in your mysql table.VladSun wrote:Then you'll have to normalize your tables.
Changes:
<input type="checkbox" name="industries[]" value="Ecommerce" /></input><label for="Ecommerce">Ecommerce</label>
<input type="checkbox" name="industries[]" value="IT - Web Design" /></input><label for="IT - Web Design">IT - Web Design</label>
now when you submit the form if you do <pre><? print_r($_POST); ?></pre> you'll see there's a nice 'industries' array with only the industries that were checked. You can turn that array into a comma separated list of values and save it all in 1 field in your table.
I've you're going to need to edit existing data with this form I'd suggest having another table with all possible industry areas and using the id of those records as the values of the checkboxes.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP Check boxes
Also an XHTML syntax note:
There are two types of tags;
singular, and surrounding. Input tags are the singular type. Same with IMGs. Divs are surrounding. Same with tables, etc.
Singular ex:
Surrounding ex:

There are two types of tags;
singular, and surrounding. Input tags are the singular type. Same with IMGs. Divs are surrounding. Same with tables, etc.
Singular ex:
Code: Select all
<input type="text" name="text-box" value="Type into this box" />Code: Select all
<div style="width: 80%">Text here</div>