forked from murtaza98/BookZone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookmark.php
executable file
·58 lines (52 loc) · 1.98 KB
/
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
<?php
function customPageHeader(){
}
?>
<?php include "./templates/header.php"; ?>
<?php
if(isset($_GET['book_id']) && isset($_GET['type']) && isset($_SESSION['username'])){
$type = $_GET['type'];
$book_id = $_GET['book_id'];
$username = $_SESSION['username'];
switch($type){
case "addToBookmark":
$query = "INSERT INTO bookmark(username,book_id,date) VALUES('$username','$book_id',now())";
break;
case "removeFromBookmark":
$query = "DELETE FROM bookmark WHERE username = '{$username}' AND book_id = '{$book_id}'";
break;
default:
$query = null;
break;
}
if($query != null){
$query_result = mysqli_query($connection,$query);
if(!$query_result){
die("<script>
window.location.href = 'book_details.php';
window.alert('Already bookmarked');
</script>");
}else{
echo "<script>
window.location.href = 'book_details.php';
window.alert('Added to bookmark');
</script>";
}
}
// $book_id = $_GET['book_id'];
// $username = $_SESSION['username'];
// $query = "INSERT INTO bookmark(username,book_id,date) VALUES('$username','$book_id',now())";
// $query_result = mysqli_query($connection,$query);
// if(!$query_result){
// die("<script>
// window.location.href = 'book_details.php';
// window.alert('Already bookmarked');
// </script>");
// }else{
// echo "<script>
// window.location.href = 'book_details.php';
// window.alert('Added to bookmark');
// </script>";
// }
}
?>