I have a set of checkboxes being displayed on a page, the name of each tag is "categories", and the value depends on the Category ID. So it would look something like this:
<input type="checkbox" name="categories" value="1">Scenic<br>
<input type="checkbox" name="categories" value="2">3D<br>
<input type="checkbox" name="categories" value="3">Animals<br>
So I'm trying to add the categories into a table, along with the corresponding image ID. I use a while loop to accomplish this. The problem is it will only add the last selected element (for example, if they all were checked it would only add 3". I figured the array is probably pointing to its last element, so I do:
$categories = reset($categories);
and get this warning.
Warning: Variable passed to reset() is not an array or object
Checked php.net and someone posted that reset() can cause problems with form input data because PHP thinks you're passing in a scalar. They listed a code snippet they created, but I edited it to fit my needs:
$c = 0;
$sql = "INSERT INTO $table2_name SET wallpaperID=$wallpaperID, categoryID=$categories[$c]";
$result = mysql_query($sql,$cnx) or die("Could not execute query. The error is on the SQL or connection line.<br>Your entered query is: $sql");
But still, it's only adding the last selected element. Any ideas?