Ok, first off, I applogize if this question has been asked before, I've spent the last 12 hours sifting through hundreds of forum threads and haven't found one that answers this question exactly yet so here goes.
I have a page that I built that has a userlist that is autopopulated as users log in, and each users has a checkbox that allows the host to select users and removed them if needed. I am using jQuery to send an array string to a php page where I am attempting to explode the string, walk through the userids and remove the passed ids from our database. It all works exceedingly well, unless I select more than one user. When I select more than one user and pass the array to the php handler, it explodes the array but only keeps the last value in the array, the rest of it is lost somewhere in the blackhole of scripting.
Here is my code from my javascript page:
function rem_user() {
var ids = $('input:checkbox[id=del]:checked').map(function(){
return this.value
}).get();
alert(ids);
jQuery("#rem_msg").load(controlpage, {AdmFnc: "rem_user", del_ids: ids}, getUsers);
}
this array is then passed to the php controlling page where it is handled by:
if (strcmp($AdmFnc, rem_user) == 0){
echo "";
$ids = trim($_POST['del_ids']);
$ids = explode(',',$ids);
if(is_array($ids)){
foreach($ids as $userid){
mysqli_query($dbc, "UPDATE webcastlogin SET logoutTime = '$current_time' WHERE userid = '$userid'") or die('Error setting logout time '.mysqli_error($dbc));
mysqli_query($dbc, "DELETE FROM weekly_users WHERE userid = '$userid'") or die('Error removing users '.mysqli_error($dbc));
}
echo 'Selected IDs removed';
} else if (empty($ids)) {
echo 'Code is wrong, no array sent';
} else {
mysqli_query($dbc, "UPDATE webcastlogin SET logoutTime = '$current_time' WHERE userid = '$ids'");
mysqli_query($dbc, "DELETE FROM weekly_users WHERE userid = '$ids'");
echo 'Selected ID removed';
}
}
As you can see on my javascript, i have an alert set up so i can verify that the information being sent is correct, as far as i can tell from that alert, it's a ","
delimited array so that's what i'm using on the php side to explode it.
I am at my wits end trying to figure out why when I run this thru the foreach loop i only get the value of the final item in the array.
Any help would be greatly appreciated and may save my hair for some future coding challanges.
Thanks