$db = new mysql_db(SERVER, USERNAME, PASSWORD, DATABASE); $errortext_contact = ""; $errortext_friend = ""; $errortext_foe = ""; //apache config set REQUEST_METHOD GET as default, automatically add / after the linke if ($_SERVER["REQUEST_METHOD"] == "GET") { if (!empty($_GET["contact"])) { rmExist($_SESSION["username"], $_GET["contact"]); $errortext_contact = "remove " . $_GET["contact"] . " from contact list successfully"; } else { if (!empty($_GET["friend"])) { rmExist($_SESSION["username"], $_GET["friend"]); $errortext_friend = "remove " . $_GET["friend"] . " from friend list successfully"; } else { if (!empty($_GET["foe"])) { rmExist($_SESSION["username"], $_GET["foe"]); $errortext_foe = "remove " . $_GET["foe"] . " from foe list successfully"; } } } $contacts = getContacts($_SESSION["username"]); $friends = getFriends($_SESSION["username"]); $foes = getFoes($_SESSION["username"]); render("contact_template.php", ["contacts" => $contacts, "friends" => $friends, "foes" => $foes, "errortext_contact" => $errortext_contact, "errortext_friend" => $errortext_friend, "errortext_foe" => $errortext_foe, "titile" => "Contact"]); } else { if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!empty($_POST["contact"])) { if ($_POST["contact"] === $_SESSION["username"]) { $errortext_contact = "can't add yourself"; } else { if (existUser($_POST["contact"]) === 0) {
function addContact($userid1, $userid2) { if (existType($userid2, $userid1) == 1) { return 0; } rmExist($userid1, $userid2); $query = "insert into contact values ('{$userid1}','{$userid2}', 3)"; $insert = mysql_query($query); if (!$insert) { die("Could not insert into the database: <br />" . mysql_error()); } return 1; }