techiefreak05 Posted September 5, 2006 Share Posted September 5, 2006 i have a site where u can have fruebds.. a profile,etc. and for every users. it displays some info and a REMOVE FRIEND button ....and when i click the REMOVE FRIEND BUTTON.. it removes a random friend .... sometimes it removes the right friend....... most times not .. whats wrong .. heres the code:[code]<center><?php $user = $_SESSION[username];$result = mysql_query("SELECT count(*) FROM `friends` WHERE `username` = '$user' AND `accepted` = 'yes'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);$new = $row[0];if($new == ""){$new = "0";}if($new != "0" ){?>You have <b><? echo $new; ?></b> Friends<?}?></center><table align="center"><tr><td bgcolor="#3399CC"><?php$query = mysql_query("SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes'");while ($array = mysql_fetch_array($query)){$to=$array['friend'];echo "<br><center><b>" .$to. "</b></center>";echo "<a href='sendMessage.php?to=" .$to. "'>-Message " .$to. "-</a> |<a href='getInfo.php?user=" .$to."'> -Get Info-</a> | <a href='http://zycoworld.com/" .$to. "'>-View zPage-</a><br><form action=\"\" method=\"post\"> <table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"delete\" value=\"-Remove-\"></td></tr></table></form>";}$user = $_SESSION[username];$query = mysql_query("SELECT * FROM friends WHERE `username` = '$user' AND `accepted` = 'yes'");$array = mysql_fetch_array($query);$friend=$array['friend'];if($_POST['delete']){mysql_query("DELETE FROM friends WHERE username = '$user' AND friend = '$friend' LIMIT 1");mysql_query("DELETE FROM friends WHERE username = '$friend' AND friend = '$user' LIMIT 1");echo "<font color=red> The User has been removed from your friends list, please refresh to view changes.</font>";}?></td></tr></table>[/code]what is wrong !?!?!?!? ??? ??? ??? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 5, 2006 Share Posted September 5, 2006 The problem here is that you are setting the $friend variable from the result of your "SELECT * ..." query above. Then you are deleting THAT friend. You need to check the $_POST data to see which friend should be deleted.This means that you need to submit the friend to be deleted along with the form. For example[code]<input type=hidden name=friend value="$to"> (this must go inside each form, inside the while loop. It will ensure that $_POST['friend'] is set when the form is submitted)...if($_POST['delete']){ $friend_to_delete = $_POST['friend'] mysql_query("DELETE FROM friends WHERE username = '$user' AND friend = '$friend_to_delete' LIMIT 1"); mysql_query("DELETE FROM friends WHERE username = '$friend_to_delete' AND friend = '$user' LIMIT 1"); echo "<font color=red> The User has been removed from your friends list, please refresh to view changes.</font>";}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.