-   Programming (
-   -   checkboxes in php [on/off] (

ALInux 11-09-2005 06:20 AM

checkboxes in php [on/off]
I want to add a checkbox to my form that should act as a on off regulator..........I googled but the only results I found were related to multiple checkboxes.........can anybody tell me how to check if a single checkbox is checked ?

fouldsy 11-09-2005 06:40 AM

Something like this would be in your form:

<input type='checkbox' name='a1'<?php if( $row["a1"] == '1') { echo "CHECKED"; } ?>>Block / Unblock Website
which is then read in by your processing script as such:

$a1 = $HTTP_POST_VARS["a1"];
In that case, my script is querying a MySQL database, working out whether an option should be ticked, and then ticking or unticking the check box. Has about 30 options dynamically handled, with the procesing script updating the choices the user makes. You can call it something other than 'a1' and then simply read in your named variable whilst processing. If it's unchecked, the result is 'off', if ticked, the result is 'on'. A quick check to process different commands based on it's value would be:

if ($a1 === 'on') {
                $a1 = 1;

Hope it helps, otherwise let us know what you're trying to do.

All times are GMT -5. The time now is 10:43 PM.