1
+ <?php include ("header.inc.php " ); ?>
2
+ </div>
3
+ <section class="panel panel-default" style="border:none;">
4
+ <div class="row">
5
+ <div class="col-md-12" style="margin-bottom:20px;">
6
+ <div class="row">
7
+ <h3 style="text-align:left; margin-left:20px;">
8
+ <i class="fa fa-plus"></i> Add Meal
9
+ </h3>
10
+ <?php
11
+ if (isset ($ _POST ['addmeal ' ])){
12
+ function protect ($ field ){
13
+ $ string =htmlentities ($ field ,ENT_QUOTES );
14
+ $ string = mysql_real_escape_string (trim (strip_tags (addslashes ($ field ))));
15
+ return $ string ;
16
+ }
17
+ $ meal = ucfirst (protect ($ _POST ['meal ' ]));
18
+ $ price = protect ($ _POST ['price ' ]);
19
+ $ category = ucfirst ($ _POST ['category ' ]);
20
+
21
+ $ target_dir = "images/ " ;
22
+ $ target_file = $ target_dir . basename ($ _FILES ["picture " ]["name " ]);
23
+ $ uploadOk = 1 ;
24
+ $ imageFileType = pathinfo ($ target_file ,PATHINFO_EXTENSION );
25
+ // Check if image file is a actual image or fake image
26
+ if (isset ($ _POST ["submit " ])) {
27
+ $ check = getimagesize ($ _FILES ["picture " ]["tmp_name " ]);
28
+ if ($ check !== false ) {
29
+ echo "File is an image - " . $ check ["mime " ] . ". " ;
30
+ $ uploadOk = 1 ;
31
+ } else {
32
+ echo "<div class ='alert alert-info'>File is not an image.</div> " ;
33
+ $ uploadOk = 0 ;
34
+ }
35
+ }
36
+
37
+ // Check file size
38
+ if ($ _FILES ["picture " ]["size " ] > 5000000 ) {
39
+ echo "<div class ='alert alert-info'>Sorry, your file is too large.</div> " ;
40
+ $ uploadOk = 0 ;
41
+ }
42
+
43
+ // Allow certain file formats
44
+ if ($ imageFileType != "jpg " && $ imageFileType != "png " && $ imageFileType != "jpeg "
45
+ && $ imageFileType != "gif " ) {
46
+ echo "<div class ='alert alert-info'>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</div> " ;
47
+ $ uploadOk = 0 ;
48
+ }
49
+
50
+
51
+ $ filename = $ _FILES ["picture " ]["tmp_name " ];
52
+ $ rand = mt_rand ();
53
+ $ picture = 'Meal ' ."_ " .$ rand ."" .$ rand ."_ " .'CU ' .". " .$ imageFileType ;
54
+
55
+
56
+ // Check if $uploadOk is set to 0 by an error
57
+ if ($ uploadOk == 0 ) {
58
+ echo "<div class ='alert alert-info'>Sorry, your file was not uploaded.</div> " ;
59
+ // if everything is ok, try to upload file
60
+ } else {
61
+ if (move_uploaded_file ($ filename ,"images/meals/ " .$ picture )) {
62
+
63
+ //Sql Insert/Update....
64
+
65
+ $ query30 = "INSERT INTO meals (meal, category, price, picture,trash)
66
+ VALUES (' $ meal', ' $ category', ' $ price',' $ picture', 'NO') " ;
67
+ $ result30 = mysql_query ($ query30 ) or die ("Couldn't execute query30 " );
68
+ echo ("<script>location.href = 'meal.php?category= $ category';</script> " );
69
+ // header('Location: meals.php');
70
+
71
+ } else {
72
+ echo "Sorry, there was an error uploading your file. " ;
73
+ }
74
+ }
75
+ }
76
+ ?>
77
+ <form action="add_meal.php" method="POST" enctype="multipart/form-data" class="form-horizontal form-label-left input_mask">
78
+ <div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
79
+ <div class="col-md-2 col-sm-12 col-xs-12">
80
+ Meal Name
81
+ </div>
82
+ <div class="col-md-6 col-sm-12 col-xs-12">
83
+ <input type="text" class="form-control has-feedback-left" name="meal" id="inputSuccess2" placeholder="Meal Name" required>
84
+ </div>
85
+ </div>
86
+ <div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
87
+ <div class="col-md-2 col-sm-12 col-xs-12">
88
+ Meal Price
89
+ </div>
90
+ <div class="col-md-6 col-sm-12 col-xs-12">
91
+ <input type="number" class="form-control has-feedback-left" name="price" id="inputSuccess2" placeholder="1000" required>
92
+ </div>
93
+ </div>
94
+ <div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
95
+ <div class="col-md-2 col-sm-12 col-xs-12">
96
+ Meal Category
97
+ </div>
98
+ <div class="col-md-6 col-sm-12 col-xs-12">
99
+ <input type="text" class="form-control has-feedback-left" name="category" id="inputSuccess2" placeholder="Category" required>
100
+ </div>
101
+ </div>
102
+ <div class="col-md-12 col-sm-12 col-xs-12 form-group has-feedback">
103
+ <div class="col-md-2 col-sm-12 col-xs-12">
104
+ Meal Picture
105
+ </div>
106
+ <div class="col-md-6 col-sm-12 col-xs-12">
107
+ <input type="file" class="form-control has-feedback-left" name="picture" id="inputSuccess2" required>
108
+ </div>
109
+ </div>
110
+ <div class="col-md-12 col-sm-12 col-xs-12">
111
+ <div class="col-md-6 col-sm-6 col-xs-12">
112
+ <a href="meals.php" class="btn btn-default">Cancel</a>
113
+ </div>
114
+ <div class="col-md-6 col-sm-6 col-xs-12">
115
+ <button type="submit" name="addmeal" class="btn btn-info"> <i class="fa fa-plus"></i> Add Meal</button>
116
+ </div>
117
+ </div>
118
+ </form>
119
+ </div>
120
+
121
+ </div>
122
+ </div>
123
+ <?php include ("footer.inc.php " ); ?>
0 commit comments