-
Notifications
You must be signed in to change notification settings - Fork 0
/
addproduct.php
152 lines (143 loc) · 5.44 KB
/
addproduct.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
<?php include("adminhead.php");?>
<?php
if(isset($_POST["submit"])){
$sql="select max(pid) from product";
$result=mysqli_query($conn,$sql);
$mrow=mysqli_fetch_array($result);
$mrow=$mrow["max(pid)"]+1;
$name=$_POST["name"];
$desc=$_POST["description"];
$mat=$_POST["material"];
$cat=$_POST["category"];
$img=$_FILES['img'];
$fname="./img/".$_FILES['img']['name'];
$sql="insert into product values($mrow,'$name','$cat','$desc','$mat','$fname','')";
mysqli_query($conn,$sql);
move_uploaded_file($img['tmp_name'],$fname);
Redirect("viewproducts.php");
}
?>
<?php
if(isset($_POST["update"])){
$pid=$_POST["pid"];
$name=$_POST["name"];
$desc=$_POST["description"];
$cat=$_POST["category"];
$mat=$_POST["material"];
$sql="update product set name='$name',category=$cat,description='$desc',material='$mat' where pid='$pid'";
mysqli_query($conn,$sql);
move_uploaded_file($img['tmp_name'],$fname);
}
?>
<?php
if(isset($_GET["pid"])){
$sql="select * from product where pid=".$_GET["pid"];
$result=mysqli_query($conn,$sql);
while($rows=mysqli_fetch_array($result)){?>
<div class="adminright flex flex-col">
<form method="post" action="" class="form card" enctype="multipart/form-data">
<table>
<tbody>
<tr>
<td>Product ID</td>
<td>
<input type="text" name="pid" id="pid" value=<?php echo $rows['pid']?>>
</td>
</tr>
<tr>
<td>Product name</td>
<td>
<input type="text" name="name" id="name" value=<?php echo $rows['name']?>>
</td>
</tr>
<tr>
<td>category</td>
<td>
<input type="text"name="category" id="category" value='<?php echo $rows['category']?>'>
</td>
</tr>
<tr>
<td>description</td>
<td>
<textarea name="description" id="" cols="16" rows="5">
<?php echo $rows['description']?>
</textarea>
</td>
</tr>
<tr>
<td>Product material</td>
<td>
<input type="text"name="material" id="material" value=<?php echo $rows['material']?>>
</td>
</tr>
<tr>
<td>
<div>curr file: <?php echo $rows['img']?></div>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Update" name="update" id="update">
</td>
</tr>
</tbody>
</table>
</form>
</div>
<?php
}
?>
<?php
}
else{
?>
<div class="adminright flex flex-col">
<form method="post" action="" class="form card" enctype="multipart/form-data">
<table>
<tbody>
<tr>
<td>Product name</td>
<td>
<input type="text" name="name" id="name">
</td>
</tr>
<tr>
<td>description</td>
<td>
<textarea name="description" id="" cols="16" rows="5">
</textarea>
</td>
</tr>
<tr>
<td>category</td>
<td>
<input type="text"name="category" id="category">
</td>
</tr>
<tr>
<td>Product material</td>
<td>
<input type="text"name="material" id="material">
</td>
</tr>
<tr>
<td>Image</td>
<td>
<input type="file" name="img" id="img" accept=".jpg,.jpeg,.png" >
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" name="submit" id="submit">
</td>
</tr>
</tbody>
</table>
</form>
</div>
<?php
}
?>
</div>
</body>
</html>