I have a signup form that has checkboxes with categories that have values that come from a table. If I were to select the third and fifth checkbox and press submit, the values that get inserted into the table are the first and second one in the array and not the third and fifth. Here is the code that I use:
join.php - This is where I select the checkboxes
$query = "SELECT * FROM categories order by cat_id";
$result = mysql_db_query($database, $query) or die(mysql_error());
if ($result)
{
while ($arr = mysql_fetch_array($result)) {
$cat_id = $arr["cat_id"];
$cat_name = $arr["cat_name"];
print "<INPUT TYPE=\"checkbox\" NAME=\"categories[]\">";
print "<input type=\"hidden\" name=\"cat_select[]\" value=\"$cat_id\" > ";
} //while
}//if
register.php - Enter the info into the database which is passed by the post method
$entries = sizeof($cat_select);
for($x = 0; $x < $entries; $x++)
{
if(isset($categories[$x]))
{
$query = "insert into user_cats (user_cat_id,user_id,cat_id) values (NULL, $user_id, $cat_select[$x])";
$result = mysql_db_query($db_name, $query);
if (!$result)
{
print "error in for loop";
die(mysql_error());
break;
}
} //if cat
}//for
If I echo categories[x], I get 'on' for the first two elements when I should get it for the third and fifth. What am I doing wrong? TIA.