I have a problem with a particular array in a checkbox input.
$insert .= '<tr>
<td>' .$uname. '</td>
<td>' .$fname. '</td>
<td>' .$lname. '</td>
<td>' .$email. '</td>
<td>'.(($admin == 'y') ? 'Admin':'User').'</td>
<td><input type="checkbox" name="change['.$uid.']"
value="'.(($admin == 'y')?'n':'y').'"/>'
.(($admin == 'y')?'Make a user':'Make an admin user').'</tr>';
From what i’ve been reading, this should create an array that can be run through if there are multiple checkbox. The $uid is the user id and the name displays as change[1], change[2] etc.. and this works.
The problem is when i run this through a while statement like so:
while(list($key, $val) = each($_POST['change'])) {
I get this message:
Warning: Variable passed to each() is not an array or object
Does anyone know why this may be happening and how to solve it?
Your array is not being created when submitted. I took your code and made the required form etc.
var_dump($_POST['change']);returns NULL, even when I remove the $uid.I wish I could tell you why, but it looks like it ‘should’ work to me.
I suggest cleaning up your code, taking out the ternary operators to something more aesthetically pleasing, then double checking your quotes. PHP hates single quotes, even when they should theoretically work, like in the parameter of your POST array (‘change’) , it is possible the quotes are confusing it.
Well PHP doesn’t hate single quotes, you just have to be careful with them as if they are used incorrectly it means code will not be parsed…