Actually that wouldn't work becuase if you tested this you would have
noticed that no name or value at all is passed for a checkbox or radio
button that is not checked.

<input type="checkbox" name="a" value="1">
<input type="checkbox" name="b" value="1" checked>
<input type="checkbox" name="c" value="1" checked>

In this example $_POST['a'] is not set so you can not check it in a
conditional statement.  One possible solution here is to use Radio Buttons
instead of check boxes.

<input type="checkbox" name="a" value="0" checked><input type="checkbox"
name="a" value="1">
<input type="checkbox" name="b" value="0"><input type="checkbox" name="b"
value="1" checked>
<input type="checkbox" name="c" value="0"><input type="checkbox" name="c"
value="1" checked>

It's a bit more cumbersome visually but it's the proper way to get the
functionality you want.  Now $_POST['a'] is set and contains 0.

-Kevin

----- Original Message -----
From: "Paul Kaiser" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 24, 2002 3:35 PM
Subject: [PHP] Quick way to test series of integers


> Hey there,
>
> I have around 50 checkboxes on an HTML form. Their "value" is "1". So,
> when a user check the box, then no problem -- the value returned by the
> form is "1" and I can enter that into my SQL database.
>
> HOWEVER...
>
> If the user does not check the box, I'm in trouble, because the "value"
> does not default to "0", but rather <nil> I'm guessing...
>
> mysql query doesn't like my trying to pass NOTHING.
>
> I COULD go through each of the 50 returned variables and, if they are not
> "1", assign "0" to them.
>
> But I'm wondering if there is a better way to go about this??
>
> Thanks,
> Paul
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to