Can't find the friend's id to store it to the database
<p>I'm really struggling with this now for a while and can't seem to get it working. In members.php (where I show all the registered users) I have a list printed out with a link "ADD TO FRIENDS" next to each user.</p>

<p>I managed, for testing purposes to display each members id well (so it gets the ID) but when I click the link it directs to the friends.php where it seems the fault is in. <strong>I don't know how to get that friend's id I clicked on IN THE friends.php file.</strong> Please have a look!</p>

<p><strong>members.php</strong></p>

<pre><code>&lt;?php
        include 'connect.php';
        include 'header.php';

        if(isset($_SESSION['signed_in']) == false || isset($_SESSION['user_level']) != 1 )
            {
                //the user is not an admin
                echo '&lt;br/&gt;';
                echo 'Sorry! You have to be &lt;a href="/signin.php"&gt;&lt;b&gt;logged in&lt;/b&gt;&lt;/a&gt; to view all the &lt;a href="signup_2.php" title="Become a registered user!"&gt;&lt;b&gt;registered&lt;/b&gt;&lt;/a&gt; members.';
                echo '&lt;br/&gt;&lt;br/&gt;';
            }
            else
            {
                echo '&lt;h2&gt;Registered users:&lt;/h2&gt;';

                $sql    = "SELECT * FROM users ORDER BY user_name ASC";
                $result = mysql_query($sql);

                $num=mysql_numrows($result);

                $i=0;
                while ($i &lt; $num)
                {
                    //$name = mysql_result($result,$i,"user_name");
                    //$id = mysql_result($result,$i,"user_id");
                    //$picture = mysql_result($result,$i,"pic_location");

                    //?friend_id="'. $id .'
                    while($user = mysql_fetch_array($result)){
                        echo $user['user_name'].'&lt;br/&gt;&lt;br/&gt;&lt;a href="friends.php?user='.$user['user_id'].'"&gt;ADD TO FRIENDS&lt;/a&gt;&lt;br/&gt;';
                        echo $user['user_id'];
                        echo '&lt;br/&gt;&lt;br/&gt;';
                    }

                    $i++;
                }

                ///////////////////////////////
                /// adding users as friends ///
                ///////////////////////////////

                //while($user = mysql_fetch_array($result))
                //echo $user['user_name'].' 
                    //&lt;a href="addfriend.php?user='.$user['id'].'"&gt;ADD TO FRIENDS&lt;/a&gt;&lt;br/&gt;';


                //NOW I WANT TO MAKE A SPECIFIC "ADD AS FRIEND" LINK NEXT TO EACH USER


            }
            include 'footer.php';
?&gt;
</code></pre>

<p>As I said I'm not sure how to get this so please have a look! Thanks!</p>

<p>J</p>

<p><strong>friends.php</strong></p>

<pre><code>&lt;?php
    include "connect.php";
    include "header.php";

    if(isset($_SESSION['signed_in']) == false || isset($_SESSION['user_level']) != 1 )
    {
        //the user is not an admin
    echo '&lt;br/&gt;';
    echo 'Sorry! You have to be &lt;a href="/signin.php"&gt;&lt;b&gt;logged in&lt;/b&gt;&lt;/a&gt; if you want to add the person as a friend!';
    echo '&lt;br/&gt;&lt;br/&gt;';
    }
    else
    {
        $sql = "SELECT * FROM users";
        $result = mysql_query($sql);

                //friend_id is the ID of the friend that is clicked on...
                //HOW DO I GET THAT ID THAT IS CLICKED ON IN THE WHILE "loop" in members.php?

                $friends = ("INSERT INTO friends SET user_id='" . $_SESSION['user_id'] . "', friend_id='".$id."', status='0'");
                $result_friends = mysql_query($friends);


                if(!$friends)
                {
                    //When you can't add this person as a friend this error will show!
                    echo 'You cannot add this user at this time. Please try again later!';
                }  
                else
                {
                    //When the friend is now added to the system!
                    echo 'Great! Now the user needs to approve before you can be friends!';
                }
    }
?&gt;
</code></pre>
