Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Location
    London
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_POST returns only last array number

    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..

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,084
    Thanks
    11
    Thanked 100 Times in 98 Posts
    $_POST['del_mem']; is now an array... run this...

    PHP Code:
    <?
    foreach($_POST['del_mem'] as $k=>$v){
      
    $sql "DELETE FROM `members` WHERE friend_id='$v' AND user_id='$uid' ";
      echo 
    $sql//mysql_query($sql);
    }
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Location
    London
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by DaSe; 12-04-2010 at 01:12 AM.

  • #4
    New to the CF scene
    Join Date
    Dec 2010
    Location
    London
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •