-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
172 lines (159 loc) · 7.04 KB
/
edit.php
File metadata and controls
172 lines (159 loc) · 7.04 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
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
164
165
166
167
168
169
170
171
172
<html>
<head>
<title>Edit a book</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="admin.php" style="color: white;">View books</a>
</li>
<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
session_start();
global $var;
include "dbconnect.php";
$PID=$_GET['ID'];
$query = "SELECT * FROM products WHERE PID='$PID'";
$result = mysqli_query ($con,$query)or die(mysql_error());
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
echo '
<div class="container" style="width:50%;">
<h2 class="text-center p-3">Edit a book</h2>
<form class="form p-3" role="form" method="post" action="edit.php" enctype="multipart/form-data" accept-charset="UTF-8" style="border: 1px solid black; border-radius: 25px;">
<div class="form-group">
<label class="sr-only" for="pid">Product ID</label>
<input type="text" name="pid" class="form-control" value="'. $row["PID"] . '" required>
</div>
<div class="form-group">
<label class="sr-only" for="title">Title</label>
<input type="text" name="title" class="form-control" value="'. $row["Title"] . '" required>
</div>
<div class="form-group">
<label class="sr-only" for="Author">Author</label>
<input type="text" name="author" class="form-control" value="'.$row["Author"].'" required>
</div>
<div class="form-group">
<label class="sr-only" for="price">Price</label>
<input type="number" name="price" class="form-control" value="'.$row["Price"].'" required>
</div>
<div class="form-group">
<label class="sr-only" for="available">No. of copies</label>
<input type="number" name="available" class="form-control" value="'. $row["Available"] .'" required>
</div>
<div class="form-group">
<label class="sr-only" for="publisher">Publisher</label>
<input type="text" name="publisher" class="form-control" value="'.$row["Publisher"].'" required>
</div>
<div class="form-group">
<label class="sr-only" for="category">Category</label>
<input type="text" name="category" class="form-control" value="'.$row["Category"].'" required>
</div>
<div class="form-group">
<label class="sr-only" for="description">Description</label>
<textarea rows="5" name="description" class="form-control" required>
'.$row['Description'] .'
</textarea>
</div>
<div class="form-group">
<label class="sr-only" for="page">No. of pages</label>
<input type="number" name="page" class="form-control" value="'.$row["page"].'" required>
</div>
<div class="form-group">
<label class="sr-only" for="weight">Weight</label>
<input type="number" name="weight" class="form-control" value="'.$row["weight"].'" required>
</div>
<div class="form-group p-3">
<br>
<div class="form-group">
<input type="file" id="myFile" name="my_file">
</div><br>
<button type="submit" name="submit" value="edit" class="btn btn-primary">
Edit
</button>
<button type="submit" name="submit" value="delete" class="btn btn-danger" style="float:right;">
Delete
</button>
</div>
</form>
</div>';
}
}
if(isset($_POST['submit']))
{
if($_POST['submit']=="edit")
{
$pid=$_POST['pid'];
$title=$_POST['title'];
$author=$_POST['author'];
$price=$_POST['price'];
$available=$_POST['available'];
$publisher=$_POST['publisher'];
$category=$_POST['category'];
$description=$_POST['description'];
$page=$_POST['page'];
$weight=$_POST['weight'];
$query ="UPDATE products SET
Title = '$title ',
Author = ' $author ',
Price = ' $price',
Available = '$available',
Publisher = '$publisher',
Description = ' $description',
Category = ' $category ',
page = '$page',
weight = '$weight'
WHERE PID = '$pid'";
$result=mysqli_query($con,$query);
if (($_FILES['my_file']['name']!="")){
$info = pathinfo($_FILES['my_file']['name']);
$ext = $info['extension'];
$newname = $pid.'.jpg';
$target = 'img/books/'.$newname;
move_uploaded_file($_FILES['my_file']['tmp_name'],$target);
}
print'
<script type="text/javascript">
alert("Successfully edited book!!!");
window.location.href = "admin.php";
</script>
';
}
else if($_POST['submit']=="delete")
{
$pid=$_POST['pid'];
$query ="DELETE from products WHERE PID = '$pid'";
$result=mysqli_query($con,$query);
unlink('img/books/'.$pid.'.jpg');
print'
<script type="text/javascript">
alert("Successfully deleted book!!!");
window.location.href = "admin.php";
</script>
';
}
}
?>
</div>
</body>
</html>