View Full Version : $_POST returns only last array number

12-04-2010, 01:46 AM
Hello guys...If I can ask you for some support that would be great..

The problem is this: I have a table of users to be deleted. I placed a checkbox next to each user in a table. The checkboxes are added witihin PHP script and the name of the checkbox is an array. But the $_POST returns only last value regardless and the rest of the users' pics return 0. When you place a title into the checkbox the title returns correct user_id. For now I have no clue why I can delete only the latest pic.

Here's the code:

in a while loop:
$mem_dir_add_pic .= "<a href='see_member.php?id=$user_id'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a>";

$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' value='".$user_id."'/></span></form>";


$mem_check = $_POST['del_mem'];

if ($mem_check == $user_id) {

$proceed = mysql_query("DELETE FROM `members` WHERE friend_id='$mem_check' AND user_id='$uid' ");

Regards and thanks for any comments..

12-04-2010, 01:55 AM
$_POST['del_mem']; is now an array... run this...

foreach($_POST['del_mem'] as $k=>$v){
$sql = "DELETE FROM `members` WHERE friend_id='$v' AND user_id='$uid' ";
echo $sql; //mysql_query($sql);

12-04-2010, 02:02 AM
That would be lovely :) ...
But no.. it doesn't work.. I've been trying to loop the input and the thing is - it only returns the latest value..in your code it deletes also the latest pic and returns value 1. So I can not delete other pic unless I delete the recent one. Then the next one in the line will get deleted but not the following etc. It really is a big nuisance..I spent good all day trying to work this out. Thank you for your replies by the way guys..

P.S. It looks like no matter what you're trying to do name='del_mem[]' doesn't store an array...only the last value. But when you insert title into the checkbox - the title returns correct each pic id from the checkbox that is placed to each pic.

12-04-2010, 03:12 AM
I am positive now that name='del_mem[]' doesn't store array. I've used is_array function and it returned error:" Variable passed to each() is not an array ". So in other words the array function from checkboxes doesn't work when checkboxes are inserted within PHP. There must be a workaround I guess..