I have a check box for which a user can check many values . I need to get the value of the check box in a variable in PHP to insert it into the database . Please someone help me ..
How to get the check box value using POST method in PHP ?
Collapse
X
-
Tags: None
-
MartinBaril
a checkbox can't have many value, it's ON or OFF. In php you don't receive unchecked checkbox.
exemple
you will get an array of checked box. for exemple, you check cat and pig, you'll get for print_r($pet);Code:Cat <input type="checkbox" name="pet[]" value="cat"> Dog <input type="checkbox" name="pet[]" value="dog"> Pig <input type="checkbox" name="pet[]" value="pig">
Code:Array ( [0] => cat [1] => pig ) -
Mohammad Shahid
there are different ways to play with checkboxes using php, see below code
Code:<?php echo $_REQUEST['a']."<br />"; echo $_REQUEST['b']."<br />"; echo print_r($_REQUEST['c'])."<br />"; ?>
orCode:<form action="" method="post"> <input type="checkbox" name="a" value="a"> <input type="checkbox" name="b" value="b"> <input type="submit" name="Submit" value="Submit"> </form>
Code:<form action="" method="post"> <input type="checkbox" name="c[]" value="c1"> <input type="checkbox" name="c[]" value="c2"> <input type="submit" name="Submit" value="Submit"> </form>
Last edited by Dormilich; Nov 3 '10, 06:37 AM. Reason: please use [CODE] [/CODE] tags when posting codeComment
-
Comment