-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaddContact.php
More file actions
31 lines (26 loc) · 895 Bytes
/
Copy pathaddContact.php
File metadata and controls
31 lines (26 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
session_start();
include './database.php';
if(!isset($_COOKIE['username'])) {
header('Location: index.php');
}
setcookie('username', $_SESSION['username'], 0);
//grab the name of the user the logged in user wants to add
$contact = $_GET['contact'];
//get currently logged in user
$username = $_GET['username'];
//check if user exists
// if so add user
$sqlStatement = "SELECT * FROM Users WHERE username='".$contact."'";
$results = executeStatement($sqlStatement);
if(count($results) <= 0 || $contact == $username){
$_SESSION["error"] = "error";
header('Location: contacts.php');
}
else{
//add user to contact
$sqlStatement = "INSERT INTO Contacts VALUE('".$username."','".$contact."')";
executeStatement($sqlStatement);
header('Location: contacts.php');
}
?>