forked from priyesh18/book-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inbooks.php
137 lines (86 loc) · 2.96 KB
/
inbooks.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
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({selector:'textarea'});
</script>
</head>
<body bgcolor="skyblue">
<form action="inbooks.php" method="post" enctype="multipart/form-data">
<table align="center" width="795" border="2" bgcolor="#187eae">
<tr align="center">
<td colspan="7"><h2>Insert New Post Here</h2></td>
</tr>
<tr>
<td align="right"><b>Author:</b></td>
<td><input type="text" name="author" size="60" required/></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name="product_keywords" size="50" required/></td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="60" required/></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" /></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" >
<option>Select a Category</option>
<?php
$get_cats = "select * from category";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats)){
$cat_title = $row_cats['name'];
echo "<option value='$cat_title'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr align="center">
<td colspan="7"><input type="submit" name="insert_post" value="Insert Product Now"/></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//getting the text data from the fields
$product_title = $_POST['product_title'];
$product_cat= $_POST['product_cat'];
$product_author = $_POST['author'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting the image from the field
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"assets/images/$product_image");
$insert_product = "INSERT INTO `Books`(`author`, `keywords`, `title`, `price`, `image`, `description`, `category`) VALUES ('$product_author','$product_keywords','$product_title','$product_price','$product_image','$product_desc','$product_cat')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "Product Has been inserted!";
echo "<script>window.open('inbooks.php','_self')</script>";
}
}
?>