├── .vscode
└── settings.json
├── add.php
├── database.php
├── delete.php
├── edit.php
├── home.php
├── index.php
├── login.php
├── logout.php
├── partials
├── footer.php
├── header.php
└── navbar.php
├── register.php
├── sql
└── setup.sql
└── static
├── css
└── index.css
├── img
├── background.jpg
└── logo.png
└── js
└── welcome.js
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "[php]": {
3 | "editor.tabSize": 2
4 | },
5 | "[html]": {
6 | "editor.tabSize": 2
7 | },
8 | "[javascript]": {
9 | "editor.tabSize": 2
10 | },
11 | "files.insertFinalNewline": true,
12 | "editor.fontSize": 24,
13 | "editor.lineHeight": 26,
14 | "terminal.integrated.fontSize": 24,
15 | "window.zoomLevel": 2
16 | }
17 |
--------------------------------------------------------------------------------
/add.php:
--------------------------------------------------------------------------------
1 | prepare("INSERT INTO contacts (user_id, name, phone_number) VALUES ({$_SESSION['user']['id']}, :name, :phone_number)");
24 | $statement->bindParam(":name", $_POST["name"]);
25 | $statement->bindParam(":phone_number", $_POST["phone_number"]);
26 | $statement->execute();
27 |
28 | $_SESSION["flash"] = ["message" => "Contact {$_POST['name']} added."];
29 |
30 | header("Location: home.php");
31 | return;
32 | }
33 | }
34 | ?>
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | = $error ?>
47 |
48 |
49 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/database.php:
--------------------------------------------------------------------------------
1 | query("SHOW DATABASES") as $row) {
11 | // print_r($row);
12 | // }
13 | // die();
14 | } catch (PDOException $e) {
15 | die("PDO Connection Error: " . $e->getMessage());
16 | }
17 |
--------------------------------------------------------------------------------
/delete.php:
--------------------------------------------------------------------------------
1 | prepare("SELECT * FROM contacts WHERE id = :id LIMIT 1");
15 | $statement->execute([":id" => $id]);
16 |
17 | if ($statement->rowCount() == 0) {
18 | http_response_code(404);
19 | echo("HTTP 404 NOT FOUND");
20 | return;
21 | }
22 |
23 | $contact = $statement->fetch(PDO::FETCH_ASSOC);
24 |
25 | if ($contact["user_id"] !== $_SESSION["user"]["id"]) {
26 | http_response_code(403);
27 | echo("HTTP 403 UNAUTHORIZED");
28 | return;
29 | }
30 |
31 | $conn->prepare("DELETE FROM contacts WHERE id = :id")->execute([":id" => $id]);
32 |
33 | $_SESSION["flash"] = ["message" => "Contact {$contact['name']} deleted."];
34 |
35 | header("Location: home.php");
36 |
--------------------------------------------------------------------------------
/edit.php:
--------------------------------------------------------------------------------
1 | prepare("SELECT * FROM contacts WHERE id = :id LIMIT 1");
15 | $statement->execute([":id" => $id]);
16 |
17 | if ($statement->rowCount() == 0) {
18 | http_response_code(404);
19 | echo("HTTP 404 NOT FOUND");
20 | return;
21 | }
22 |
23 | $contact = $statement->fetch(PDO::FETCH_ASSOC);
24 |
25 | if ($contact["user_id"] !== $_SESSION["user"]["id"]) {
26 | http_response_code(403);
27 | echo("HTTP 403 UNAUTHORIZED");
28 | return;
29 | }
30 |
31 | $error = null;
32 |
33 | if ($_SERVER["REQUEST_METHOD"] == "POST") {
34 | if (empty($_POST["name"]) || empty($_POST["phone_number"])) {
35 | $error = "Please fill all the fields.";
36 | } else if (strlen($_POST["phone_number"]) < 9) {
37 | $error = "Phone number must be at least 9 characters.";
38 | } else {
39 | $name = $_POST["name"];
40 | $phoneNumber = $_POST["phone_number"];
41 |
42 | $statement = $conn->prepare("UPDATE contacts SET name = :name, phone_number = :phone_number WHERE id = :id");
43 | $statement->execute([
44 | ":id" => $id,
45 | ":name" => $_POST["name"],
46 | ":phone_number" => $_POST["phone_number"],
47 | ]);
48 |
49 | $_SESSION["flash"] = ["message" => "Contact {$_POST['name']} updated."];
50 |
51 | header("Location: home.php");
52 | return;
53 | }
54 | }
55 | ?>
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | = $error ?>
68 |
69 |
70 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/home.php:
--------------------------------------------------------------------------------
1 | query("SELECT * FROM contacts WHERE user_id = {$_SESSION['user']['id']}");
13 |
14 | ?>
15 |
16 |
17 |
18 |
19 |
20 |
21 | rowCount() == 0): ?>
22 |
23 |
24 |
No contacts saved yet
25 |
Add One!
26 |
27 |
28 |
29 |
30 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Store Your Contacts Now
6 |
Get Started
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/login.php:
--------------------------------------------------------------------------------
1 | prepare("SELECT * FROM users WHERE email = :email LIMIT 1");
14 | $statement->bindParam(":email", $_POST["email"]);
15 | $statement->execute();
16 |
17 | if ($statement->rowCount() == 0) {
18 | $error = "Invalid credentials.";
19 | } else {
20 | $user = $statement->fetch(PDO::FETCH_ASSOC);
21 |
22 | if (!password_verify($_POST["password"], $user["password"])) {
23 | $error = "Invalid credentials.";
24 | } else {
25 | session_start();
26 |
27 | unset($user["password"]);
28 |
29 | $_SESSION["user"] = $user;
30 |
31 | header("Location: home.php");
32 | }
33 | }
34 | }
35 | }
36 | ?>
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | = $error ?>
49 |
50 |
51 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/logout.php:
--------------------------------------------------------------------------------
1 |
2 |