i have a problem with my php code that I just cannot figure out. I have an array defined accordingly: $choice = ($_POST['choice']); and used in a form: <input type="checkbox" name="choice[]" id="choice[]" value="1" <?php if(isset($_POST['choice']) == 1){ echo "checked=\"checked\""; } ?>/> <p> <input type="checkbox" name="choice[]" id="choice[]" value="2" <?php if(isset($_POST['choice']) == 2){ echo "checked=\"checked\""; } ?>/> <p> the script works fine, sending data to the database and retrieving it on a CMS interface, but i still get the following error when I press submit in the form: Notice: Undefined index: choice in /Applications/MAMP/htdocs/FINALFORM/subscribe.php on line 26 I tried correcting this by putting in isset: $choice = isset($_POST['choice']); and the error in gone, but then the data doesn't send to database etc. any ideas? also, i can't seem to get my sticky forms to work on it. it checks both checkboxes even though one has only been selected. btw, it has to be an array because of settings in the database.
replace your $_POST['choice'] to : $choice1 = isset($_POST['choice'][0]) ? $_POST['choice'][0] : 0; $choice2 = isset($_POST['choice'][1]) ? $_POST['choice'][1] : 0; <input type="checkbox" name="choice[]" id="choice[]" value="1" <?php if($choice1 == 1){ echo "checked=\"checked\""; } ?>/> <p> <input type="checkbox" name="choice[]" id="choice[]" value="2" <?php if($choice2 == 2){ echo "checked=\"checked\""; } ?>/> <p> PHP: There is one thing that you need to understand , any inputs with the name as : name[] , will be stored in the $_POST/$_GET as an array : In this case if both checkboxes are checked : $_POST['choice'] = "0" => "1" "1" => "2"