tags:

views:

21

answers:

2

i have a database patient with 3-4 tables n each table has about 8 attributes.... i have a table medical history which has attribute additional info ... under which i have 5 checkboxes.... all the values entered are taken up except the chekbox values..... plz help

A: 

you can use checkbox attribute checked and according to it u can set a flag for inserting in database. marc's way of doing is quite effective...

ricky
Man that's ugly code. Why not do something like `$box02 = isset($_POST['box02'])`. That directly assigns 1 or 0 to the variable without wasting 4 lines on brackets and else clauses. As well, why build the query with concatenation? PHP is perfectly capable of interpolating the variables into a double-quoted string withouth having to slap in all the extra quotes/concat operators: `"INSERT INTO..... VALUES ($box01, $box02)"`
Marc B
A: 

How are you constructing your fields? Do they all have the same name attribute? Do they have a name attribute at all? Is there a value attribute?

<input type="checkbox" name="testfield" value="somevalue" />
<input type="checkbox" name="testfield" value="othervalue" />

If you're constructing the checkboxes like that, then PHP will by default ignore all but the last value submitted (it overwrites previous values with new ones), like this:

$_POST = array(
   'testfield' => 'othervalue'
)

You have to force PHP into 'array mode' for this type of construct, by adding [] to the name attribute:

<input type="checkbox" name="testfield[]" value="somevalue" />
<input type="checkbox" name="testfield[]" value="othervalue" />

This will allow multiple values to be submitted under the same name, and you'll end up with an array in your _GET/_POST arrays:

$_POST = array(
   'testfield' => array('somevalue', 'othervalue')
)

Of course, only the checkboxes which are actually checked will be sent with the form data.

Check that your form is properly constructed by putting a var_dump($_POST); (or GET or REQUEST) in the form handling part of the script and see if the checkbox values are actually being sent. Perhaps you're looking for the wrong name attribute, the tags could be malformed in the form, etc...

Marc B