-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewBook.php
127 lines (99 loc) · 4.83 KB
/
viewBook.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
session_start();
//connect to database
require_once('connDB.php');
// Check connection
if ($conn === false) {
die("ERROR: Could not connect. " . mysqli_connect_error());
}
if ($_SESSION['userType'] != 1) {
header("Location: home.php");
}
$userType = 1;
if (!isset($_SESSION['username'])) {
header("Location: home.php");
exit();
} else {
$username = $_SESSION['username'];
$userType = 1;
}
isset($_POST['selectedBook']) ? $selectedBook = $_POST['selectedBook'] : $selectedBook = $_GET['selectedBook'];
$getBooksQuery = "SELECT title, author, price, genre, ISBN, stock, imgPath, description FROM book WHERE ISBN=$selectedBook;";
$values = $conn->query($getBooksQuery);
$row = mysqli_fetch_array($values);
# Check if book is already in cart
$getCartQuery = "SELECT * FROM cart WHERE ISBN='$selectedBook' AND username='$username';";
$cartValues = $conn->query($getCartQuery);
$cartRow = mysqli_fetch_array($cartValues);
$button = "<p class='pb-5' style='color: white;'>Add to Cart</p>";
if (mysqli_num_rows($cartValues) > 0) {
$button = "<img src='images/check.svg' alt='My Happy SVG' class='pb-4' />";
}
$quantity = 1;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$addedBook = $row;
$quantity = $_POST['quantity'];
$addToCartQuery = "INSERT INTO cart VALUES ('" . $username . "', '" . $row['title'] . "', '" . $row['author'] . "', " . $row['price'] . ", '" . $row['ISBN'] . "', " . $quantity . ", '" . $row['imgPath'] . "', " . $row['stock'] . ")";
$conn->query($addToCartQuery);
$button = "<img src='images/check.svg' alt='My Happy SVG' class='pb-4' />";
}
?>
<!DOCTYPE>
<head>
<link href="viewBook.css" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<title>LittyLit</title>
<link href='https://fonts.googleapis.com/css?family=Nunito' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Girassol' rel='stylesheet'>
</head>
<body>
<main>
<?php include 'elements/header.php' ?>
<a href="customer-browseCatalog.php" class="GoBack pb-4"><b>
<< Go Back</b></a>
<div class="container">
<div class="row">
<div class="col-lg-4 pt-4 pb-4 text-center" id="top">
<img class="pic" src="<?php echo $row['imgPath'] ?>" alt="Place Holder Book" style="width:210px;height:350px;">
</div>
<div class="col-lg-5 pt-4 pb-4 text-left mr-5" id="middle" style="margin-left: -2rem;">
<h1 class="TitleInfo"><?php echo $row['title'] ?></h1>
<a href="customer-browseCatalog.php?authorSearch=<?php echo $row['author'] ?>">
<h3 class="AuthorInfo pt-2"><?php echo $row['author'] ?></h3>
</a>
<div class="row pt-2 pr-2">
<div class="col text-left">
<p><?php echo $row['description'] ?></p>
</div>
</div>
</div>
<div class="col-lg-2 p-3 pt-5 pb-4 text-center" id="bottom">
<div class="row justify-content-center pt-5 pb-2" style="margin-bottom: -2rem;">
<h1 class="PriceInfo" style="font-size: 2rem;"><?php echo "$" . number_format($row['price'], 2) ?></h1>
</div>
<form method="post">
<button class="AddCart" name="addedBook"><?php echo $button ?></button>
<p class="InventoryText mt-2 mr-1"><b>Quantity:</b></p>
<select class="form-select" style="border-radius: 0.3rem; border-color: white;" name="quantity">
<?php for ($i = 0; $i <= $row['stock']; $i++) {
if ($i == $quantity) { ?>
<option style="font-weight: bolder;" value="<?php echo $i ?>" selected> <?php echo $i ?>
</option>
<?php }
else { ?>
<option style="font-weight: bolder;" value="<?php echo $i ?>"> <?php echo $i ?>
</option>
<?php }
} ?>
</select><br><br>
</form>
</div>
</div>
</div>
<?php include 'elements/footer.html' ?>
</main>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</body>
</html>