Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2011, 12:03 PM   PM User | #1
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
removing "friends" using radio buttons help please

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:

PHP Code:

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:

PHP Code:
 <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
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags

Last edited by Dan13071992; 11-13-2011 at 07:46 PM..
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 04:36 PM   PM User | #2
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
$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?
Adee is offline   Reply With Quote
Old 11-13-2011, 05:05 PM   PM User | #3
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags

Last edited by Dan13071992; 11-13-2011 at 05:09 PM..
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 05:22 PM   PM User | #4
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
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.
Adee is offline   Reply With Quote
Old 11-13-2011, 05:25 PM   PM User | #5
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
PHP Code:
<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?
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 05:52 PM   PM User | #6
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
PHP Code:
<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.";
    }
?>
Adee is offline   Reply With Quote
Old 11-13-2011, 05:55 PM   PM User | #7
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
using what you just gave me it comes up wiuth "You have removed A from your friends list. "
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 05:58 PM   PM User | #8
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
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
Adee is offline   Reply With Quote
Old 11-13-2011, 05:59 PM   PM User | #9
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
yes but without the auto refresh
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 06:04 PM   PM User | #10
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
Here's the code for that, w/o the auto refresh:
PHP Code:
$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

Last edited by Adee; 11-13-2011 at 06:08 PM..
Adee is offline   Reply With Quote
Old 11-13-2011, 06:09 PM   PM User | #11
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
do you have the database table for this?
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 06:11 PM   PM User | #12
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
Quote:
Originally Posted by Dan13071992 View Post
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.
Adee is offline   Reply With Quote
Old 11-13-2011, 06:12 PM   PM User | #13
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
well mine has the username of the logged in player, and 'person' which is the friend that has been added.
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Old 11-13-2011, 06:26 PM   PM User | #14
Adee
Regular Coder

 
Join Date: Jul 2010
Location: Oregon City
Posts: 280
Thanks: 5
Thanked 50 Times in 49 Posts
Adee can only hope to improve
Quote:
Originally Posted by Dan13071992 View Post
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]
Adee is offline   Reply With Quote
Old 11-13-2011, 06:49 PM   PM User | #15
Dan13071992
Regular Coder

 
Join Date: Dec 2010
Location: Kent, UK
Posts: 573
Thanks: 23
Thanked 10 Times in 10 Posts
Dan13071992 is an unknown quantity at this point
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.
__________________
http://360-tactics.co.uk/forum/index.php

Crime-Wave

please post your code wrapped in tags
please post your PHP wrapped in tags
Dan13071992 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:20 AM.


Advertisement
Log in to turn off these ads.