-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_product.php
161 lines (125 loc) · 4.15 KB
/
add_product.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
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
<?php
include("connection.php");
include("Inc_admin_dash.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Products</title>
<!--Font Awesome and online Links --->
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<!--style1 css--->
<link rel="stylesheet" href="dash_css/style1.css">
<!--End Here--->
<body>
<div id="page-wrapper" class="gray-bg dashbard-1">
<div class="content-main">
<!--banner-->
<div class="banner">
<h2>
<a href="index.php">Home</a>
<i class="fa fa-angle-right"></i>
<span>Dashboard</span>
</h2>
</div>
<div class="grid-form">
<div class="grid-form1">
<h3 id="forms-example" class="">Add New Products</h3>
<hr>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<h4 style="padding-left:20px;">Product Name</h4>
<input type="text" name="product" class="form-control cat" required="">
</div>
<div class="form-group">
<h4 style="padding-left:20px;">Product Price</h4>
<input type="number" name="price" class="form-control cat" required="">
</div>
<div class="form-group">
<h4 style="padding-left:20px;">Product Details</h4>
<div class="form-group">
<textarea class="form-control cat" name="detail" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
</div>
<div class="form-group">
<h4 style="padding-left:20px;">Product Category</h4>
<div class="form-group">
<select class="form-control cat" name="category" id="exampleFormControlSelect1">
<option value="0">Select Category</option>
<!--PHP Code -->
<?php
$fetch = "select * from category";
$run_fetch = mysqli_query($con,$fetch);
while($row = mysqli_fetch_array($run_fetch))
{
echo "
<option>$row[1]</option>
";
}
?>
<!-- End Here -->
</select>
</div>
</div>
<div class="form-group">
<h4 style="padding-left:20px;">Product Brand</h4>
<div class="form-group">
<select class="form-control cat" name="brand" id="exampleFormControlSelect1">
<option value="0">Select Brands</option>
<!--PHP Code -->
<?php
$fetch = "select * from brand";
$run_fetch = mysqli_query($con,$fetch);
while($row = mysqli_fetch_array($run_fetch))
{
echo "
<option>$row[1]</option>
";
}
?>
<!-- End Here -->
</select>
</div>
</div>
<div class="form-group">
<h4 style="padding-left:20px;">Product Image</h4>
<input type="file" name="txtfile" class="form-control cat">
</div>
<button style="border-radius:10%; margin-left:20px;" name="btn" type="submit" class="btn btn-dark">Save</button>
<!-- PHP Start -->
<?php
if(isset($_POST['btn']))
{
$pd_name = $_POST['product'];
$pd_price = $_POST['price'];
$pd_detail = $_POST['detail'];
$pd_category = $_POST['category'];
$pd_brand = $_POST['brand'];
$filename = $_FILES["txtfile"]["name"];
$oldLocation = $_FILES["txtfile"]["tmp_name"];
$newlocation = "images/".$filename;
move_uploaded_file($oldLocation,$newlocation);
$query = mysqli_query($con,"insert into products (p_name,p_price,p_details,p_category,p_brand,p_img)
values ('$pd_name','$pd_price','$pd_detail','$pd_category','$pd_brand','$filename')");
if($query > 0)
{
echo"
<div style='margin-top:5px;' class='alert alert-success' role='alert'>
<b>Successfull!</b> Product $pd_name has been inserted..
</div>
";
}
else
{
echo "<script>alert('Failed!')</script>";
}
}
?>
<!-- End Here -->
</form>
</div>
</body>
</html>