This cannot work, if both variables contain arrays. You need to update the items one by one (or use a clumsy MySql CASE statement, which I won't explain here):
foreach ($userrole as $key => $role) {
$query = "UPDATE members SET userrole ='$role'
WHERE member_id = '$member_id[$key]'";
// perform query ...
}
Or if only $member_id is an array:
$query = "UPDATE members SET userrole ='$userrole'
WHERE member_id IN ('" . implode(',', $member_id) . "')";
// perform query ...
You should further rename your variables to reflect that they are arrays. Just use the plural:
$userrole => $userroles
$member_id => $member_ids
On more thing: Are these values coming from a HTML form? If yes, you should really sanitize them using mysql_escape_string()
. This can be done for multiple values at once using array_map()
:
$userroles = array_map('mysql_escape_string', $userroles);
$member_ids = array_map('mysql_escape_string', $member_ids);