Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_POST returns only last value from an array 1

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hello guys...

If I may ask you for help regarding checkboxes values..The boxes are names into array but $_POST returns only the last value. Here's the code:

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) || ($mem_check2 == $user_id))  { 

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


}


The thing that checkboxes values or title returns correct user_id . But $_POST returns only the last array id of the last inserted picture to be deleted. Thank you for any help.

 
I have very little idea what you are talking about.

However as you have abandoned this it seems irrelevant. I posted previously simply so that other readers would not be confused, by reading the thread, into thinking that checkboxes did not work in the documented fashion.
 
P.S. (No 2) In other words - it is pure "delete all / delete only selected members" option.

But for now I had to use different method - and made the page wihout checkboxes for now. Works fine but lacks the option "delete selected" that I wanted to do through checkboxes array. Regards.

 
No - your explanation is fantastic ! - is just a bit of misunderstanding. I hope I could explain it more clearly now. Thank you !

 
...a one more question to you. I am logged in - I have 2 members to delete - member with id 230 and member 240. My friend is also logged in - he has 4 members to delete - 240 ,250,260 and 270. So I need to have 2 checkboxes next to each user and my friend needs to have 4 checkboxes next to their users. I cannot simplify it more. Anyway - as I said I worked around the problem by using a different strategy. Cheers !

 
that seems to be a simple implementation of permissions logic. nothing to do with how to submit multiple checkboxes in a form.

 
I see*...




*I mean - I really see...probably should've formed my questions differently.

 
This is what I exactly wanted:

Code:
while ($row = mysql_fetch_assoc($result)) { 
echo '<input type="checkbox" value="1" name="somename['.$row['id'].']"> Username: $row[username]';
}

This will return an array of somename[], filled with 1's, 

ie..

somename['32'] = 1;
somename['35'] = 1;

if they are checked. If they are not checked... they wont return anything.

Thank you guys nonetheless...!


 
Jpadie as much as I would like to admit I can't really. In your 5/12 post at 10:10 you mentioned similar thing but you wrote an array where each box would've been named differently:

Code:
<form method="post">
<input type="checkbox" name="test[1]" value="on" />test 1<br/>
<input type="checkbox" name="test[2]" value="on" />test 2<br/>
<input type="checkbox" name="test[3]" value="on" />test 3<br/>
<input type="checkbox" name="test[4]" value="on"/>test 4<br/>
<input type="submit" />
</form>

Whereas there must be only one instance of the checkbox within PHP that changes the name dynamically and moreover will come up as many times as the number of the members that are fetched by the '$rows'. So indeed one of solution was to put one instance within while loop with concatenation of the 'name + $rows'. So not exactly the same but close...close but no cigar as the lovely saying goes. Thank you muchly jpadie I gave you a handful of stars so far for your replies. See you soon..

 
quite! the point of my post was to show that the KEY is the important element here. not the value.
your business logic/permissions implementation was not the subject of this post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top