-
Notifications
You must be signed in to change notification settings - Fork 2
/
item.php
163 lines (141 loc) · 4.97 KB
/
item.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
include('header.php');
include_once('conn.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.row {
padding: 5px;
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
opacity: 1;
}
</style>
</head>
<body>
<div class="container mt-3 mb-5" align="center">
<?php
$id = $_GET['bookId'];
if (isset($_SESSION['id'])) {
$uid = $_SESSION['id'];
}
$qry = mysqli_query($conn, "select * from books where bookId='$id'"); // select query
$qty = mysqli_fetch_array($qry); // fetch data
$sql = "SELECT * FROM books Where bookID=$id";
$result = mysqli_query($conn, $sql);
if (!$result) {
exit;
}
if ($result->num_rows == 0) {
return null;
} else {
$rowcount = $result->num_rows;
$pdts = $result->fetch_assoc();
?>
<form action="" method="post">
<div class="card" style="background-color:#EFEDF2">
<div class="row">
<div class="card-body">
<div class="col-md-12">
<center>
<img class="card-img-top pt-2" style="height: 200px; width:150px" src="<?php echo $pdts["bookImage"] ?>" alt="Card image cap">
<div class="card-body pt-1">
<p><b><?php echo $pdts["bookName"] ?></b></p>
<p>Year: <?php echo $pdts["bookPublishyear"] ?><b> | </b><?php echo $pdts["bookLanguage"] ?><b> | </b>Pages: <?php echo $pdts["bookPages"] ?></p>
<p>Size: <?php echo $pdts["bookSize"] ?>MB</p>
<input type="submit" name="download" class="btn btn-success" value="Download" disabled>
</div>
</center>
</div>
</div>
</div>
</div>
</form>
<div id="accordion" class="mt-2" align="left">
<div class="card">
<div class="card-header" align="center">
<a class="card-link active" data-toggle="collapse" href="#collapseOne">
Author
</a>
<a class="collapsed card-link" data-toggle="collapse" href="#collapseTwo">
Short Description
</a>
</div>
<div id="collapseOne" class="collapse show" data-parent="#accordion">
<div class="card-body">
<?php echo $pdts["bookAuthor"] ?>
</div>
</div>
<div id="collapseTwo" class="collapse" data-parent="#accordion">
<div class="card-body">
<?php echo $pdts["bookShortDesc"] ?>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</body>
<?php
if (isset($_POST['cart'])) // when click on cart button
{
$quantity = $_POST['quantity'];
// $pid = $_POST['pid'];
$price = $_POST['price'];
$name = $_POST['name'];
$res = mysqli_query($conn, "SELECT * FROM cartdetails WHERE UserID='$uid' AND bookID='$id'");
$row = mysqli_num_rows($res);
if ($row === 0) {
$sql = "INSERT INTO `cartdetails`(`bookID`, `UserID`,`bookQuantity`,`bookPrice`,`bookName`) VALUES ('$id','$uid','$quantity','$price','$name')";
$query = mysqli_query($conn, $sql);
if ($query) {
?>
<script>
window.location = "cart.php";
</script>
<?php
}
} else {
?>
<script>
alert('<?php echo $name ?> is already in the cart');
</script>
<?php
exit();
}
}
if (isset($_POST['buy'])) // when click on buy now button
{
$quantity = $_POST['quantity'];
// $pid = $_POST['pid'];
$price = $_POST['price'];
$name = $_POST['name'];
$res = mysqli_query($conn, "SELECT * FROM cartdetails WHERE UserID='$uid' AND bookID='$id'");
$row = mysqli_num_rows($res);
if ($row === 0) {
$sql = "INSERT INTO `cartdetails`(`bookID`, `UserID`,`bookQuantity`,`bookPrice`,`bookName`) VALUES ('$id','$uid','$quantity','$price','$name')";
$query = mysqli_query($conn, $sql);
if ($query) {
?>
<script>
window.location = "buy.php?bookID=<?= $pdts['bookID']; ?>";
</script>
<?php
}
} else {
?>
<script>
alert('<?php echo $name ?> is already in the cart');
</script>
<?php
exit();
}
}
?>
<?php include('footer.php'); ?>
</html>