开发者

to take values of checkbox in table attributes

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 ... 开发者_C百科under which i have 5 checkboxes.... all the values entered are taken up except the chekbox values..... plz help


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜