-
Notifications
You must be signed in to change notification settings - Fork 6
/
add-bookmark.php
82 lines (61 loc) · 2.06 KB
/
add-bookmark.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// Fetching all the Functions and DB Code
require('./includes/functions.inc.php');
require('./includes/database.inc.php');
// Creates a session or resumes the current one based on a session identifier.
session_start();
// If user not logged in
if(!isset($_SESSION['USER_LOGGED_IN'])) {
// Redirected to login page along with a message
alert('Please log in to Add Bookmarks');
redirect('./user-login.php');
}
// If we dont get article_id from URL
if(!isset($_GET['id'])) {
// Redirect to home page
redirect('./index.php');
}
// If we get article_id from URL and it is null
elseif ($_GET['id'] == '') {
// Redirect to home page
redirect('./index.php');
}
// If we get article_id from URL and it is not null
else {
// Store the article_id in a variable
$article_id = $_GET['id'];
}
// Article Query to fetch all the article data for respective article id
$articleQuery = " SELECT *
FROM article
WHERE article_id = {$article_id}
AND article_active = 1";
// Running the Article Query
$res = mysqli_query($con, $articleQuery);
// Returns the number of rows from the result retrieved.
$row = mysqli_num_rows($res);
// If no article found with respective article id
if($row == 0) {
// Redirect to home page
redirect('./index.php');
}
// Bookmark Query to insert bookmark record for the particular user and article
$bookmarkQuery = " INSERT INTO bookmark
(user_id,article_id)
VALUES
('{$_SESSION['USER_ID']}', '{$article_id}')";
// Running Bookmark Query
$result = mysqli_query($con, $bookmarkQuery);
//If Query ran successfully
if($result) {
// Redirected to home page along with a message
alert("Bookmark Added Successfuly");
redirect('./bookmarks.php');
}
// If the Query failed
else {
// Redirected to home page along with a message
alert('Try Again Later');
redirect('./index.php');
}
?>