-
Notifications
You must be signed in to change notification settings - Fork 1
/
editfood.php
110 lines (90 loc) · 3.78 KB
/
editfood.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
<?php
include_once "connection/conn.php";
?>
<?php include_once "file/header.php"; ?>
<section class="contentsection clear">
<?php include_once "file/sidebar.php"; ?>
<article class="maincontent clear">
<div class="content">
<h2>Update food name & price & Image</h2>
<?php
if (isset($_GET["food_id"]) and $_GET["food_id"] !=NULL) {
$food_id=preg_replace("/[^a-zA-Z0-9]/", "", $_GET["food_id"]);
}else{
header("location:foodlist.php");
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"]=="POST") {
$fid=$_POST["fid"];
$fname=$_POST["fname"];
$image=$_POST["image"];
$price=$_POST["price"];
$fcategory=$_POST["fcategory"];
$image=basename($_FILES["image"]["name"]);
$target_file = "common/images/foods/$image";
move_uploaded_file($_FILES['image'], $target_file);
if ($fid=="" || $fname=="" || $image=="" || $price=="" || $fcategory=""){
echo "<span style='color:red'>no empty</span>";
}else{
$sql="UPDATE tbl_food set fid='$fid', fname='$fname', image='$image', price='$price', fcategory='$fcategory' where food_id='$food_id'";
$query=mysqli_query($connection,$sql);
if ($query !=false) {
echo "<span style='color:green'>update successfully</span>";
}else{
echo "<span style='color:green'>Error</span>";
}
}
}
?>
<form action="" method="post" enctype="multipart/data-form">
<table>
<?php
$sql="SELECT * FROM tbl_food where food_id='$food_id'";
$query=mysqli_query($connection,$sql);
if ($query !=false) {
while ($value=mysqli_fetch_array($query)) {
?>
<tr>
<td>Food Id</td>
<td><input type="text" name="fid" value="<?php echo $value['food_id'] ?>"/></td>
</tr>
<tr>
<td>Food Name</td>
<td><input type="text" name="fname" value="<?php echo $value['food_name'] ?>"/></td>
</tr>
<tr>
<td>Image</td>
<td><input type="file" name="image" value="<?php echo $value['image'] ?>"/></td>
</tr>
<tr>
<td>Food Price</td>
<td><select name="price">
<option value="">Select Pricet</option>
<option value="100">100 TK</option>
<option value="150">150 TK</option>
<option value="200">200 TK</option>
<option value="80">80 TK</option>
</select>
<?php echo $value['price'] ?>
</td>
</tr>
<br>
<tr>
<td>Food Category</td>
<td><input type="text" name="fcategory" value="<?php echo $value['food_category'] ?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Update"/></td>
</tr>
<?php }} ?>
</table>
</form>
</div>
</article>
</section>
<?php include_once "file/footer.php"; ?>
</div>
</body>
</html>