This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_recipe.php
175 lines (129 loc) · 4.58 KB
/
insert_recipe.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Verify Insert</title>
<link rel="stylesheet" type="text/css" href="CSS/main.css">
</head>
<body>
<p>
<ul class = "topnav">
<li><a href = "index.html">Home</a></li>
<li class ="dropdown">
<a href="javascript:void(0)" class="dropbtn">View Recipes</a>
<div class="dropdown-content">
<a href = "all_recipes.php">View All Recipes</a>
<a href = "select_recipes_first.php">View Selected Recipe</a>
</div>
</li>
<li class ="dropdown">
<a href="javascript:void(0)" class="dropbtn">Recipes</a>
<div class="dropdown-content">
<a href = "select_ingredients.php">Insert Recipe</a>
<a href = "delete_select_recipe.php">Delete Recipe</a>
</div>
</li>
<li>
<li class ="dropdown">
<a href="javascript:void(0)" class="dropbtn">Ingredients</a>
<div class="dropdown-content">
<a href = "create_ingredients.html">Insert Ingredient</a>
<a href = "delete_select_ingredients.php">Delete Ingredients</a>
</div>
</li>
<li><a href = "about.html">About</a></li>
<li><a href = "future.html">Upcoming</a></li>
</ul>
<?php
@ $db = mysql_pconnect("localhost","recipebo_steph","secret");
if (!$db)
{
echo "ERROR: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("recipebo_webproj");
if(isset($_POST['recipename'])) {
$recipename = $_POST['recipename'];
$recipename = addslashes($recipename);
}
if(isset($_POST['quantityLg'])) $quantityLg = $_POST['quantityLg'];
if(isset($_POST['quantitySm'])) $quantitySm = $_POST['quantitySm'];
if(isset($_POST['unit'])) $unit = $_POST['unit'];
if(isset($_POST['ing'])) $ing = $_POST['ing'];
if(isset($_POST['notes'])) $notes = $_POST['notes'];
$query = "insert into recipes values
('".NULL."','".$recipename."')";
$result = mysql_query($query);
if($result) {
$query = "select last_insert_id() as lastid";
$result= mysql_query($query);
$row = mysql_fetch_array($result);
$id = htmlspecialchars( stripslashes($row["lastid"]));
echo mysql_affected_rows()." recipe added to Database.<br>";
}
$k = 0;
for ($i = 0; $i < sizeof($ing); $i++)
{
$ing[$i] = addslashes($ing[$i]);
$query = "select ingredient_id,ingredient_name from ingredients where
ingredient_name =\"".$ing[$i]."\"";
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());
$row = mysql_fetch_array($result);
$ingid = htmlspecialchars( stripslashes($row["ingredient_id"]));
$quantityLg[$i] = addslashes($quantityLg[$i]);
$quantitySm[$i] = addslashes($quantitySm[$i]);
$fraction = explode("|",$quantitySm[$i]);
$array = array($quantityLg[$i],$fraction[0]);
$storeQty = implode(" ", $array);
$total = $fraction[1] + $quantityLg[$i];
$unit[$i] = addslashes($unit[$i]);
$pieces = explode("|", $unit[$i]);
$storeOz = $total*$pieces[1];
$storeUnit = $pieces[0];
$ingid = addslashes($ingid);
$notes[$i] = addslashes($notes[$i]);
$query = "insert into recipe_ingredients values
(".$id.",'".$ingid.
"','".$storeQty.
"','".$storeUnit.
"','".$notes[$i].
"','".$storeOz."')";
$result = mysql_query($query);
if($result) $k++;
}
echo $k." ingredient(s) added to Recipe.<br>";
?>
<table border="1">
<tr>
<th>Recipe Name</th>
<th>Quantity</th>
<th>Unit</th>
<th>Ingredient</th>
<th>Special Notes</th>
</tr>
<?php
$query2 = "select r.recipe_name as n, ri.quantity as q, ri.unit as u, i.ingredient_name as ing, ri.notes as note
from recipes r join recipe_ingredients ri on r.recipe_id = ri.recipe_id
join ingredients i on ri.ingredient_id = i.ingredient_id
where r.recipe_id = ".$id."";
$result2 = mysql_query($query2) or die($query2."<br/><br/>".mysql_error());
$x = sizeof($ing);
echo "<tr>
<td rowspan='".$x."'>".$recipename."</td>";
for ($j=0; $j < sizeof($ing); $j++)
{
$row2 = mysql_fetch_array($result2);
echo "<td>";
echo htmlspecialchars( stripslashes($row2["q"]));
echo "</td><td>";
echo htmlspecialchars( stripslashes($row2["u"]));
echo "</td><td>";
echo htmlspecialchars( stripslashes($row2["ing"]));
echo "</td><td>";
echo htmlspecialchars( stripslashes($row2["note"]));
echo "</td></tr>";
}
?>
</table>
</body>
</html>