-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
137 lines (117 loc) · 4.32 KB
/
admin.php
File metadata and controls
137 lines (117 loc) · 4.32 KB
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
<html>
<head>
<title>Admin</title>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-white bg-dark" >
<div class="container-fluid">
<a class="navbar-brand" href="index.php" style="margin: -14px 0px -22px -19px;"><img class="img-responsive" alt="Brand" src="img/logo.png" style="width: 127px;margin: 0px;"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="orders.php" style="color: white;">View orders</a>
</li>
<li class="nav-item">
<a class="nav-link" href="add.php" style="color: white;">Add book</a>
</li>
</ul>
</div>
</div>
</nav>
<?php
include "dbconnect.php";
$sql = "SELECT * FROM products ORDER BY Category DESC";
$result = $con->query($sql);
if(mysqli_num_rows($result) > 0)
{
echo '
<h2 class="text-center p-3">Books</h2>
<div class = "container">
<table class="table table-bordered" id="myTable">
<thead>
<tr>
<th scope="col">Product ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Price</th>
<th scope="col">Available</th>
<th scope="col">Publisher</th>
<th scope="col">Category</th>
<th scope="col">Description</th>
<th scope="col">Page</th>
<th scope="col">Weight</th>
<th scope="col">Edit</th>
</tr>
</thead>
<tbody>
';
while($row = mysqli_fetch_assoc($result))
{
$editpg="edit.php?ID=".$row["PID"];
echo'
<tr>
<td>' . $row["PID"] . '</td>
<td>' . $row["Title"] . '</td>
<td>' . $row["Author"] . '</td>
<td>' . $row["Price"] .'</td>
<td>' . $row["Available"] . '</td>
<td>' . $row["Publisher"] . '</td>
<td>' . $row["Category"] . '</td>
<td>' . $row["Description"] . '</td>
<td>' . $row["page"] . '</td>
<td>' . $row["weight"] . '</td>
<td>
<a href="'.$editpg.'"><button type="button" class="btn btn-info m-3">Edit</button></a>
</td>
</tr>
';
}
}
echo '</tbody>
</table>
</div>';
?>
</div>
<?php
if(isset($_POST['submit']))
{
if($_POST['submit']=="Edit")
{
$username=$_POST['login_username'];
$password=$_POST['login_password'];
$query = "SELECT * from users where UserName ='$username' AND Password='$password'";
$result = mysqli_query($con,$query)or die(mysql_error());
if(mysqli_num_rows($result) > 0)
{
$row = mysqli_fetch_assoc($result);
$_SESSION['user']=$row['UserName'];
print'
<script type="text/javascript">alert("successfully logged in!!!");</script>
';
}
else
{ print'
<script type="text/javascript">alert("Incorrect Username Or Password!!");</script>
';
}
}
else if($_POST['submit']=="Delete")
{
$pid=$_POST['pid'];
$query = "DELETE from products where PID ='$pid'";
$result = mysqli_query($con,$query)or die(mysql_error());
print'
<script type="text/javascript">
console.log($pid);
alert("Deleted book!!");</script>
';
}
}
?>
</body>
</html>