-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
134 lines (125 loc) · 5.1 KB
/
add.php
File metadata and controls
134 lines (125 loc) · 5.1 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
<html>
<head>
<title>Add 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>
</ul>
</div>
</div>
</nav>
<div class="container" style="width:50%;">
<h2 class="text-center p-3">Add a book</h2>
<form class="form p-3" role="form" method="post" action="add.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" placeholder="Product ID" required>
</div>
<div class="form-group">
<label class="sr-only" for="title">Title</label>
<input type="text" name="title" class="form-control" placeholder="Title" required>
</div>
<div class="form-group">
<label class="sr-only" for="Author">Author</label>
<input type="text" name="author" class="form-control" placeholder="Author" required>
</div>
<div class="form-group">
<label class="sr-only" for="price">Price</label>
<input type="number" name="price" class="form-control" placeholder="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" placeholder="Copies" required>
</div>
<div class="form-group">
<label class="sr-only" for="publisher">Publisher</label>
<input type="text" name="publisher" class="form-control" placeholder="Publisher" required>
</div>
<div class="form-group">
<label class="sr-only" for="category">Category</label>
<input type="text" name="category" class="form-control" placeholder="Category" required>
</div>
<div class="form-group">
<label class="sr-only" for="description">Description</label>
<textarea rows="5" name="description" class="form-control" required>
</textarea>
</div>
<div class="form-group">
<label class="sr-only" for="page">No. of pages</label>
<input type="number" name="page" class="form-control" placeholder="Pages" required>
</div>
<div class="form-group">
<label class="sr-only" for="weight">Weight</label>
<input type="number" name="weight" class="form-control" placeholder="Weight in gms" required>
</div>
<br>
<div class="form-group">
<input type="file" id="myFile" name="my_file" required>
</div>
<div class="form-group p-3">
<center>
<button type="submit" name="submit" value="addbook" class="btn btn-primary">
Add book
</button></center>
</div>
</form>
</div>
<?php
session_start();
include "dbconnect.php";
if(isset($_POST['submit']))
{
$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="select * from products where PID = '$pid'";
$result=mysqli_query($con,$query) or die(mysql_error);
if(mysqli_num_rows($result)>0)
{
print'
<script type="text/javascript">alert("Book ID is taken");</script>
';
}
else
{
$query ="INSERT INTO products VALUES ('$pid','$title ','$author ','$price','$available','$publisher','$category ','$description','$page','$weight')";
$result=mysqli_query($con,$query);
if (($_FILES['my_file']['name']!="")){
$info = pathinfo($_FILES['my_file']['name']);
$newname = $pid.'.jpg';
$target = 'img/books/'.$newname;
move_uploaded_file($_FILES['my_file']['tmp_name'],$target);
}
print'
<script type="text/javascript">
alert("Successfully Added book!!!");
window.location.href = "admin.php";
</script>
';
}
}
?>
</body>
</html>