<?php
$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");
include ("inc/inc_forumname.php");
$page = "Add buddy";
$pagelink = $file;
include("inc/inc_setonline.php");
$title = "Add Buddy";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
print "<center><br><br><br><br><br> <table border=1 cellpadding=0 cellspacing=0 bordercolor=\"$bordercolor\" width=\"60%\" bgcolor=\"$fgcolour\"><tr><td><font size=$fontsize face=\"$font\" color=\"$fontcolor\"><centeR><br><br>";


//Check the users involved aren't already buddies...

$alreadybuddies = 0;
$result = mysql_query( "SELECT * FROM $buddytable WHERE strName = '$gfcookie[1]'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ( $a_row->strBuddyName == $buddyname )
    {
        $alreadybuddies = 1;
    }
}

if ($alreadybuddies == 1)
{
    print "$buddyname is already a buddy of yours!";
}
else
{
    $query = "INSERT INTO $buddytable ( strName, strBuddyName, strDateAdded ) values ( '$gfcookie[1]', '$buddyname', '$date' )";
    mysql_query( $query, $link ) or die ( "Could not add to \"$buddytable\" table: ".mysql_error() );
    print "$buddyname is now your buddy.";
}
print "<br><a href=\"javascript:history.back( )\">Click here</a> to go back, or <a href=\"buddymenu.php\">here</a> to go to your Buddy Menu.<br><br></td></tr></table>";

include("inc/inc_footer.php");