/mybookbag/processrequest.php
PHP | 54 lines | 49 code | 5 blank | 0 comment | 6 complexity | dc307d1eef677ccab61102d334323093 MD5 | raw file
- <?php
- session_start();
- include('functions.php');
- if(!isset($_POST["submit"])){
- header("Location: addfriend.php");
- }
- else{
- $username = "";
- $email = "";
- if(isset($_POST["username"])){
- $username = $_POST["username"];
- }
- else{
- $username = "";
- }
- if(isset($_POST["email"])){
- $email = $_POST["email"];
- }
- else{
- $email = "";
- }
- echo "username=$username";
- echo "email=$email";
- $targetid = determineTarget($username,$email); //Get id of targetuser
- if(!$targetid){
- $_SESSION["addresult"] = "Could not process your request somehow.";
- header("Location: addfriend.php");
- }
- else{
- if(verifyRequest($targetid)){ //Check if $id is accepted (if you're not trying to add yourself)
- $query = "insert into `friend_of`(`p_id`,`friend_id`,`accepted`) values({$_SESSION["id"]},{$targetid},1)";
- $handle = mysql_query($query);
- if(!$handle){ //If query failed, create message accordingly
- $_SESSION["addresult"] = "Could not process your request somehow. Perhaps you already tried to add this person or you are already friends with him or her.";
- }
- else{ //If not, create message accordingly
- $_SESSION["addresult"] = "Request sent!";
- }
- }
- else{ //If you tried to add yourself, create according message.
- $_SESSION["addresult"] = "You cannot add yourself you friendless bastard!";
- }
- header("Location: friends.php");
- }
- }
- function verifyRequest($targetid){ //Returns a boolean
- return($_SESSION["id"]!=$targetid);
- }
- ?>