<?php
chdir("../");
include "inc/functions.inc.php";
$mysql = new mysql(DB_MAIN);
$sel = $mysql->select(PRE."members", "id='".$_COOKIE['mid']."'", "id", "DESC", "1");
while($a=mysql_fetch_array($sel))
{
if(preg_match("#".$_POST['friend']."#", $allfriends = $a['friends']) == TRUE)
{
header("Location: ".$HTTP_REFERER."&ferror");
die();
}
}
unset($sel);
if(mysql_num_rows($mysql->select(PRE."members", "username='".$_POST['friend']."'", "id", "DESC", "1")) == "0")
{
die("No such user");
}
if(!$mysql->update(PRE."members", "friends='".$_POST['friend']."~".$allfriends."'", "id='".$_COOKIE['mid']."'"))
{
header("Location: ".$HTTP_REFERER."&ferror");
die();
} else {
header("Location: ".SITE_URL."Members/Friends");
}
$mysql->close();
?>