I am having issues with multiple check boxes.

December 17, 2010 at 16:33:16
Specs: Windows Vista
I would like my users to be able to check multiple checkboxes at a time. It only pulls the last item i selected. Please help!! This is what I have:

<label for="sports" id="label">*Choose your Sports:</label><br />
Baseball:<input type="checkbox" name="sports[]" value="baseball"><br />
Football:<input type="checkbox" name="sports[]" value="football" ><br />
Golf:<input type="checkbox" name="sports[]" value="golf" ><br />

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$number = $_POST['number'];
$address = $_POST['address'];
$address2 = $_POST['address2'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$age = $_POST['age'];

foreach ($sports as $sports)
/*echo "$sports is checked"; -*/


See More: I am having issues with multiple check boxes.

Report •

December 20, 2010 at 13:59:00
Right now you have multiple things labeled as sports[], so when it hits baseball it creates the array, then when it hits football it creates it again, then again at golf. Give each of them a unique name, then you can use $_POST['football'] or $_POST['golf'] to see if it was checked, if it was it will return TRUE or 1, if not it will return FALSE or 0, depending on how you are checking it.

Report •
Related Solutions

Ask Question