-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinsert_product.php
More file actions
145 lines (141 loc) · 7.08 KB
/
Copy pathinsert_product.php
File metadata and controls
145 lines (141 loc) · 7.08 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
<?php
if(!isset($_SESSION['user_email'])){
header('location: admin_login.php?not_admin=You are not Admin!');
}
if(isset($_POST['insert_pro'])){
//getting text data from the fields
$pro_title = $_POST['pro_title'];
$pro_cat = $_POST['pro_cat'];
$pro_brand = $_POST['pro_brand'];
$pro_price = $_POST['pro_price'];
$pro_desc = $_POST['pro_desc'];
$pro_keywords = $_POST['pro_keywords'];
//getting image from the field
$pro_image = $_FILES['pro_image']['name'];
$pro_image_tmp = $_FILES['pro_image']['tmp_name'];
move_uploaded_file($pro_image_tmp,"product_images/$pro_image");
$insert_product = "insert into products (pro_cat, pro_brand,pro_title,pro_price,pro_desc,pro_image,pro_keywords)
VALUES ('$pro_cat','$pro_brand','$pro_title','$pro_price','$pro_desc','$pro_image','$pro_keywords');";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "<h2 style='text-decoration: red'> Product has been Successfully Inserted! </h2>
<a href='view_products.php'></a>";
}
}
?>
<h1 class="text-center my-4"><i class="fas fa-plus fa-md"></i> <span class="d-none d-sm-inline"> Add New </span> Product </h1>
<form action="" method="post" enctype="multipart/form-data">
<div class="row">
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_title" class="float-md-right"> <span class="d-sm-none d-md-inline"> Product </span> Title:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-file-signature"></i></div>
</div>
<input type="text" class="form-control" id="pro_title" name="pro_title" placeholder="Enter Product Title" >
</div>
</div>
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_cat" class="float-md-right"><span class="d-sm-none d-md-inline"> Product </span> Category:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4 mt-3 mt-lg-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-list-alt"></i></div>
</div>
<select class="form-control" id="pro_cat" name="pro_cat">
<option>Select Category</option>
<?php
$getCatsQuery = "select * from categories";
$getCatsResult = mysqli_query($con,$getCatsQuery);
while($row = mysqli_fetch_assoc($getCatsResult)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</div>
</div>
</div>
<div class="row my-3">
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_brand" class="float-md-right"> <span class="d-sm-none d-md-inline"> Product </span> Brand:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-stamp"></i></div>
</div>
<select class="form-control" id="pro_brand" name="pro_brand">
<option>Select Brand</option>
<?php
$getBrandsQuery = "select * from brands";
$getBrandsResult = mysqli_query($con,$getBrandsQuery);
while($row = mysqli_fetch_assoc($getBrandsResult)){
$brand_id = $row['brand_id'];
$brand_title = $row['brand_title'];
echo "<option value='$brand_id'>$brand_title</option>";
}
?>
</select>
</div>
</div>
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_img" class="float-md-right"><span class="d-sm-none d-md-inline"> Product </span> Image:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4 mt-3 mt-lg-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="far fa-image"></i></div>
</div>
<input class="form-control" type="file" id="pro_image" name="pro_image">
</div>
</div>
</div>
<div class="row my-3">
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_price" class="float-md-right"> <span class="d-sm-none d-md-inline"> Product </span> Price:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-money-bill"></i></div>
</div>
<input class="form-control" id="pro_price" name="pro_price" placeholder="Enter Product Price">
</div>
</div>
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_kw" class="float-md-right"><span class="d-sm-none d-md-inline"> Product </span> Keyword:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4 mt-3 mt-lg-0">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-key"></i></div>
</div>
<input class="form-control" type="text" id="pro_keywords" name="pro_keywords" placeholder="Enter Product Keywords">
</div>
</div>
</div>
<div class="row my-3">
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto">
<label for="pro_desc" class="float-md-right"><span class="d-sm-none d-md-inline"> Product </span> Detail:</label>
</div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4">
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="far fa-comment-alt"></i></div>
</div>
<textarea class="form-control" type="file" id="pro_desc" name="pro_desc" placeholder="Enter Product Detail"></textarea>
</div>
</div>
</div>
<div class="row my-3">
<div class="d-none d-sm-block col-sm-3 col-md-4 col-lg-2 col-xl-2 mt-auto"></div>
<div class="col-sm-9 col-md-8 col-lg-4 col-xl-4">
<button type="submit" name="insert_pro" class="btn btn-primary btn-block"><i class="fas fa-plus"></i> Insert Now </button>
</div>
</div>
</form>