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 15 of 15
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    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
    Last edited by Dan13071992; 11-13-2011 at 08:46 PM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

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

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    $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?

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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
    Last edited by Dan13071992; 11-13-2011 at 06:09 PM.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

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

  • #4
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #6
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    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.";
        }
    ?>

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #8
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    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

  • #9
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #10
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    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 07:08 PM.

  • #11
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #12
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    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.

  • #13
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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

  • #14
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    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]

  • #15
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    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


  •  

    Posting Permissions

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