-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit_meal.php
148 lines (137 loc) · 6.62 KB
/
edit_meal.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
<?php include("header.inc.php"); ?>
</div>
<section class="panel panel-default" style="border:none;">
<div class="row">
<div class="col-md-12" style="margin-bottom:20px;">
<div class="row">
<?php
$food = $_GET['food'];
$query44 = "SELECT * FROM meals WHERE id = '$food' and trash != 'YES'";
$result44 = mysql_query($query44)
or die ("Couldn't execute query44.");
$cate = mysql_num_rows($result44);
if ($cate == '0' ) {
header("Location: meals.php");
}
while ($row44 = mysql_fetch_array($result44,MYSQL_ASSOC))
{
?>
<h3 style="text-align:left; margin-left:20px;">
<i class="fa fa-save"></i> Edit Meal
</h3>
<?php
if(isset($_POST['addmeal'])){
$food = $_GET['food'];
function protect($field){
$string=htmlentities($field,ENT_QUOTES);
$string= mysql_real_escape_string(trim(strip_tags(addslashes($field))));
return $string;
}
$meal = ucfirst($_POST['meal']);
$price = protect($_POST['price']);
$category = ucfirst($_POST['category']);
$fav = $_FILES["picture"]["name"];
if(!empty($fav)){
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["picture"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["picture"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "<div class ='alert alert-danger'>File is not an image.</div>";
$uploadOk = 0;
}
}
// Check file size
if ($_FILES["picture"]["size"] > 5000000) {
echo "<div class ='alert alert-danger'>Sorry, your file is too large.</div>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "<div class ='alert alert-danger'>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</div>";
$uploadOk = 0;
}
$filename = $_FILES["picture"]["tmp_name"];
$rand = mt_rand();
$picture = 'Meal'."_".$rand."".$rand."_".'CU'.".".$imageFileType;
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<div class ='alert alert-danger'>Sorry, your file was not uploaded.</div>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($filename,"images/meals/" .$picture)) {
//Sql Insert/Update....
$query30 = "UPDATE meals SET meal = '$meal', category = '$category', price = '$price', picture = '$picture' WHERE id = '$food'";
$result30 = mysql_query($query30) or die ("Couldn't execute query30");
echo("<script>location.href = 'meal.php?category=$category';</script>");
// header('Location: meals.php');
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}else{
$query30 = "UPDATE meals SET meal = '$meal', category = '$category', price = '$price' WHERE id = '$food'";
$result30 = mysql_query($query30) or die ("Couldn't execute query30");
echo("<script>location.href = 'meal.php?category=$category';</script>");
}
}
?>
<form action="edit_meal.php?food=<?php echo $_GET['food']; ?>" method="POST" enctype="multipart/form-data" class="form-horizontal form-label-left input_mask">
<div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
<div class="col-md-2 col-sm-12 col-xs-12">
Meal Name
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<input type="text" class="form-control has-feedback-left" name="meal" id="inputSuccess2" value="<?php echo $row44['meal']; ?>" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
<div class="col-md-2 col-sm-12 col-xs-12">
Meal Price
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<input type="number" class="form-control has-feedback-left" name="price" id="inputSuccess2" value="<?php echo $row44['price']; ?>" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
<div class="col-md-2 col-sm-12 col-xs-12">
Meal Category
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<input type="text" class="form-control has-feedback-left" name="category" id="inputSuccess2" value="<?php echo $row44['category']; ?>" required>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
<div class="col-md-2 col-sm-12 col-xs-12">
Meal Picture
</div>
<div class="col-md-6 col-sm-12 col-xs-12">
<input type="file" class="form-control has-feedback-left" name="picture" id="inputSuccess2">
</div>
<div class="col-md-2 col-sm-12 col-xs-12">
Optional
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="col-md-6 col-sm-6 col-xs-12">
<a href="meal.php?category=<?php echo $row44['category']; ?>" class="btn btn-default">Cancel</a>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<button type="submit" name="addmeal" class="btn btn-info"> <i class="fa fa-save"></i> Save</button>
</div>
</div>
</form>
<?php
}
?>
</div>
</div>
</div>
<?php include("footer.inc.php"); ?>