-
Notifications
You must be signed in to change notification settings - Fork 0
/
addFood.php
135 lines (112 loc) · 4.03 KB
/
addFood.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
<?php
require 'admin.php';
//include 'connection.php';
/*$conn = connect();
session_start();
if (isset($_SESSION["uname"])) {
$store = $_SESSION["uname"];
}
else {
header("Location: officeLogin.php");
}*/
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Add Food</title>
<link rel="stylesheet" href="addFood.css">
</head>
<body>
<div class="formvalue">
<form class="box1" method="post" enctype="multipart/form-data">
<select name="category" >
<?php
$sql = mysqli_query($conn,"SELECT category FROM category");
if (mysqli_num_rows($sql)>0) {
while ($row=mysqli_fetch_assoc($sql)) {
// echo "<option value='.$row['category'].'>".$row['category']."</option>";
echo '<option value="'.$row["category"].'">'.$row["category"].'</option>';
}
}
?>
</select>
<br>
<input type="food" name="food" placeholder="Add Food Name"><br>
<input type="number" name="price" placeholder="Enter Food Price"><br>
<input type="file" name="uploadfile" placeholder="Upload Food Image"/><br>
<input type="submit" name="add" value="Add Food">
<?php
//add button
if (isset($_POST["add"])) {
$cat = $_POST["category"];
$food = $_POST["food"];
$price = $_POST["price"];
$filename = $_FILES["uploadfile"]["name"];
$tempname = $_FILES["uploadfile"]["tmp_name"];
$folder = "image/".$filename;
$user = $_SESSION["uname"];
$check = mysqli_query($conn,"SELECT food,category FROM food WHERE food='$food' AND category = '$cat'");
if (mysqli_num_rows($check)==0) {
$add = mysqli_query($conn,"INSERT INTO food(category,food,price,image,add_by) VALUES('$cat','$food','$price','$filename','$user')");
}
else {
echo $food.' already exists in this '.$cat;
}
if (move_uploaded_file($tempname, $folder)) {
$msg = "Image uploaded successfully";
}else{
$msg = "Failed to upload image";
}
}
//finish add button
//update
?>
</form>
</div>
<table class="addfoodtable" border="1">
<caption>All Food</caption>
<tr>
<th>SL</th>
<!-- <th>id</th>-->
<th>category</th>
<th>food</th>
<th>price</th>
<th>image</th>
<th>Action</th>
</tr>
<?php
$see = mysqli_query($conn,"SELECT * FROM food");
$i=0;
if (mysqli_num_rows($see)>0) {
while ($data = mysqli_fetch_assoc($see)) {
$image = $data['image'];
//$re_img =imagescale ( $image , 30 , 20 );
echo "<tr>";
// echo "<form method='POST'>";
echo "<td>".$i."</td>";
// echo "<td>".$data['id']."</td>";
echo "<td>".$data['category']."</td>";
echo "<td>".$data['food']."</td>";
echo "<td>".$data['price']."</td>";
echo "<td>"."<img src='image/$image' height='200' width='200' >"."</td>";
echo "<form method='post'>";
echo "<td>"."<input type='submit'value='delete'name='delete$i'>"."</td>";
echo "</form>";
if (isset($_POST["delete$i"])) {
$id = $data['id'];
$cat = $data['category'];
$price = $data['price'];
$food = $data['food'];
$del = mysqli_query($conn, "DELETE FROM food WHERE id ='$id'");
}
echo "</tr>";
echo "<br>";
$i++;
}
}
//delete
?>
</table>
</body>
</html>