Greetings,
First post here, so forgive me if this is not a PHP question.
I am working with a friend who has done most of the work on this and I am posting on his behalf as well as mine.
We are trying to create a check box list which will enter the chosen values into a MySQL database.
Currently, the database entries are listed/entered only as "array", not the actual values in the form.
When a radio button list is used then the values will be entered in to the MySQL database.
However, we do not want to use radio buttons, we wish to use a check box form.
Here is the location of the form:
http://epicroadtrips.us/birdlist/form1.html
Additional files used for this are:
http://epicroadtrips.us/birdlist/confirm.html
This generates a page with the results of the checked of entries.
This was the original goal for the this form but it has evolved into something more complicated, and I think, useful.
http://epicroadtrips.us/birdlist/processor.php
As I understand it this is the file which will process the results of the list and send it to the data base.
Any help or ideas appreciated.
Thanks,
-Mike
--
http://www.EpicRoadTrips.us
Getting check box selections to a MySQL database
Moderator: General Moderators
Re: Getting check box selections to a MySQL database
Your fields are named "field7[]", "field8[]", etc. When the square brackets are in there, each field is treated as an array. The string representation of an array is just "Array" - which is what gets put into the DB. Take off the square brackets.
Also know that checkboxes that are not checked on do not get POSTed.
Also know that checkboxes that are not checked on do not get POSTed.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Getting check box selections to a MySQL database
I will get this info to one working on the code.pickle wrote:Your fields are named "field7[]", "field8[]", etc. When the square brackets are in there, each field is treated as an array. The string representation of an array is just "Array" - which is what gets put into the DB. Take off the square brackets.
That is what we want - only an entry for each selection which is checked off.pickle wrote: Also know that checkboxes that are not checked on do not get POSTed.
Thanks!
-Mike
http://www.EpicRoadTrips.us
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Getting check box selections to a MySQL database
In order to have each checkbox value entered into a database individually you will need to name each checkbox the same:
The form
The code to add values to a database
Pretty crude but hopefully gives you some insight.
The form
Code: Select all
<form name="form1" method="post"><input type="checkbox" name="chkBox[]" /><br /><input type="submit" name="submit" value="submit" /></form> Code: Select all
if(isset($_POST['submit']))
{
//GET THE CHECKBOX
$chkBox=$_POST['chkBox'];
//SIMPLY LOOP OF SELECTED CHECKBOXES
foreach($chkBox as $chk)
{
//INSERT INTO DATABASE - $chk is the checkbox value
}
}
Re: Getting check box selections to a MySQL database
Thanks. I wll pass this along to the fella who is working the code.aceconcepts wrote:In order to have each checkbox value entered into a database individually you will need to name each checkbox the same:
The formThe code to add values to a databaseCode: Select all
<form name="form1" method="post"><input type="checkbox" name="chkBox[]" /><br /><input type="submit" name="submit" value="submit" /></form>Pretty crude but hopefully gives you some insight.Code: Select all
if(isset($_POST['submit'])) { //GET THE CHECKBOX $chkBox=$_POST['chkBox']; //SIMPLY LOOP OF SELECTED CHECKBOXES foreach($chkBox as $chk) { //INSERT INTO DATABASE - $chk is the checkbox value } }
-Mike