@wastedSep 17.2008 — #<input type="checkbox" value="1" name="chkBox"> [code=php] <?php // if the checkbox is checked while posting the form $chkBox will store 1 otherwise it is empty. $chkBox = $_POST['chkbox'];
if($chkBox != ''){ // use your database insert query here } ?>[/code]
@SyCoSep 17.2008 — #<input type="checkbox" value="1" name="chkBox"> [code=php] <?php // if the checkbox is checked while posting the form $chkBox will store 1 otherwise it is empty. $chkBox = $_POST['chkbox'];
if($chkBox != ''){ // use your database insert query here } ?>[/code][/QUOTE]
Why rewrite the variable to another one for no reason?
$chkBox is not a POST super global yet it now holds the value of the POST superglobal. If you just use the POST var then you know where it came from.
Also with error handling turned up you'll get an undefined index error first time the page loads or when the form is submitted without the value checked. When a form is submitted and the checkbox was not checked it is not in the POST array so you can just look to see if it is set, then act upon it. [code=php] if(isset($_POST['chkBox'])){ // use your database insert query here } [/code] Don't rename POST/GET vars unless you have a good reason.