...

View Full Version : Resolved removing "friends" using radio buttons help please



Dan13071992
11-13-2011, 01:03 PM
hello, im having problems with my radio butons, i have two parts to this script, the first part is adding friends, the second is removing them from a list that is run using radio buttons.

the first part (adding friends) works fine, all i have to do by myself now is make it so you cannot add the same person again and again, however the part i am having trouble with is deleting the friend. both the php coding and the friends on the list that you can select to remove will be posted below.


Removing friends php script:




if(strip_tags($_POST['removesubmit']) && strip_tags($_POST['removesubmit'])){
$removePer=strip_tags($_POST['removesubmit']) && strip_tags($_POST['removesubmit']);
mysql_query("DELETE FROM `friends` WHERE `username`='$fetch->username' AND `person`='$removePer' AND `type`='Friend' LIMIT 1");

$message= "<strong>You removed $removePer from your friends list!</strong><br>";
}



Friends list to select who to remove:



<tr>
<td>Your Friends:</td><td>
<?php

$friend=mysql_query("SELECT * FROM friends WHERE username='$fetch->username' AND type='Friend' ORDER BY id");
$num_rows =mysql_num_rows($friend);

if ($num_rows == "0"){

echo "You have no friends on your friends list!";

}else{

while($friend1=mysql_fetch_object($friend)){
echo "<input type='radio' name='removesubmit' value='$friend1->person'><a href='profile.php?viewuser=$friend1->person'>$friend1->person</a><br>";
} }

?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align=right><input type="submit" name="removesubmit" id="removesubmit" value="Remove"></td>

</tr>


All that comes up when I try to remove a user is "You removed 1 from your friends list!" i dont know how its get the answer of "1".

any help would be appreciated. cheers guys.

Dan13071992

Adee
11-13-2011, 05:36 PM
$removePer isn't right. When you have something like
$removePer=strip_tags($_POST['removesubmit']) && strip_tags($_POST['removesubmit']);

If both of those are true, then $removePer is going to return 1. If both are false, it will return 0... etc.
I don't know what $_POST['removesubmit'] is, but you need to do something like

$removePer = strip_tags($_POST['removesubmit']) . strip_tags($_POST['removesubmit']);

It also seems confusing as to why you would want to remove 'person' and 'type' from your friendslist.. are there multiple types of friendslist or what?

Dan13071992
11-13-2011, 06:05 PM
person and type is due to the fact that the person is the "friends name" and type is "friend" or "blocked" so that the user has the choice of blocking a person from communicating with them or making that person a friend.

also using your code i got this message "
You removed RemoveRemove from your friends list!" it has changed from "1" to "removeremove"

Dan13071992

Adee
11-13-2011, 06:22 PM
You have the same thing in your code only it was returning 1..

$removePer=strip_tags($_POST['removesubmit']) && strip_tags($_POST['removesubmit']);

post the html code of what you're trying to access.

$_POST['removesubmit'] is what, a submit button with the value of "Remove"? $removePer should be the value of the radio button I'm thinking.

Dan13071992
11-13-2011, 06:25 PM
<tr>
<td>Your Friends:</td><td>
<?php

$friend=mysql_query("SELECT * FROM friends WHERE username='$fetch->username' AND type='Friend' ORDER BY id");
$num_rows =mysql_num_rows($friend);

if ($num_rows == "0"){

echo "You have no friends on your friends list!";

}else{

while($friend1=mysql_fetch_object($friend)){
echo "<input type='radio' name='removesubmit' value='$friend1->person'><a href='profile.php?viewuser=$friend1->person'>$friend1->person</a><br>";
} }

?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align=right><input type="submit" name="removesubmit" id="removesubmit" value="Remove"></td>

</tr>


that is the html code, with the radio buttons of the friends, friends show up there using php code and the radio buttons next to it to select who yuou want to remove, before pressing the remove button.

if u would like a screen shot i can do that?

Adee
11-13-2011, 06:52 PM
<tr>
<td>Your friends:</td>
<td>
<?php

$friend=mysql_query("SELECT * FROM friends WHERE username='$fetch->username' AND type='Friend' ORDER BY id");
$num_rows =mysql_num_rows($friend);

if ( $num_rows == "0" )
{
echo "You have no friends on your friends list!";
}
else
{
while($friend1=mysql_fetch_object($friend))
{
echo "<input type='radio' name='friend[]' value='$friend1->person'><a href='profile.php?viewuser=$friend1->person'>$friend1->person</a><br>";
}
}

?>
</td>
</tr>

<tr>
<td align="right"><input type='submit' name='remove' value='Remove Friend' /></td>
</tr>

<?php
if(isset($_POST['remove']))
{
$removePer = mysql_escape_string($_POST['friend'][0]);
$rQuery = "DELETE FROM `friends` WHERE `username`='$fetch->username' AND `person`='$removePer' AND `type`='Friend' LIMIT 1";
mysql_query($rQuery);
echo "You have removed $removePer from your friends list.";
}
?>

Dan13071992
11-13-2011, 06:55 PM
using what you just gave me it comes up wiuth "You have removed A from your friends list. "

Adee
11-13-2011, 06:58 PM
zzz is this what you're trying to do? http://rs-downfall.com/scripts/cf/friends.php
just click any friend name and then click remove

Dan13071992
11-13-2011, 06:59 PM
yes but without the auto refresh

Adee
11-13-2011, 07:04 PM
Here's the code for that, w/o the auto refresh:


$c = mysql_connect('host', 'username', 'pass');
if($c) { mysql_select_db('dbname', $c); }

$q = mysql_query("SELECT * FROM friends");

if(mysql_num_rows($q) == 0)
{
echo "no friends added.";
}
else
{
echo "<form method='post' action=''>";
while($r = mysql_fetch_array($q))
{
echo "<input name='friend[]' type='radio' value='$r[0]'>$r[0]<br />";
}
echo "</form>";

echo "<input type='submit' name='remove' value='Remove' />";
}


if(isset($_POST['remove']))
{
$f = "DELETE FROM friends WHERE name = '".mysql_escape_string($_POST['friend'][0])."'";
mysql_query($f);
echo "You removed ".$_POST['friend'][0]." from your friends list.";

}

see if you can't adapt that to what you're trying to do

Dan13071992
11-13-2011, 07:09 PM
do you have the database table for this?

Adee
11-13-2011, 07:11 PM
do you have the database table for this?

ya, but really, its just a table called 'friends' and then one field called 'name', which has the friends name in it.

Dan13071992
11-13-2011, 07:12 PM
well mine has the username of the logged in player, and 'person' which is the friend that has been added.

Adee
11-13-2011, 07:26 PM
well mine has the username of the logged in player, and 'person' which is the friend that has been added.

then $r[0] should be $r[1]

Dan13071992
11-13-2011, 07:49 PM
i foundout the answer, i only needed to take out "strip_tags($_POST['removesubmit'])" now it works. sorry for wasting your time, and thank you so much for your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum