Hi,
I am setting up a page on which users select a number of checkboxes:
PHP Code:
echo "
<ul class='checkboxes'>";
$category_query = "select * from alumni_category";
$result = @mysql_query($category_query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '
<li class="inline">
<input type="checkbox" id = "' . $row[categoryid] . '" name="'category[]" value="' . $row[categoryid] . '" /><label for= "' . $row[categoryid] . '">' . $row[category] . "</label></li>n";
}
echo '
</ul>';
}
The code to handle this is:
PHP Code:
if(isset($_POST['category']) && count($_POST['category']) !=0){
$category = array();
foreach($_POST['category'] as $val){
$category[] = $val;
}
} else {
$category = FALSE;
$errors[] = 'Please choose at least one category.';
}
The var_dump prints out the following, no matter how many checkboxes I check:
string(5) "Array" Warning: Invalid argument supplied for foreach() in mywebsite.com/test/cv.php on line 107 array(0) { }
echo var_dump($category);
Why is it posting a string saying 'Array' rather than an array of the values that I chose?
Any help would be greatly appreciated
Thanks