-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddIngredients.php
More file actions
53 lines (39 loc) · 1.52 KB
/
addIngredients.php
File metadata and controls
53 lines (39 loc) · 1.52 KB
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
<!--
Michael Nunes Principles of Database System
Dr. Stephen Blythe 30500-21
Project #3
addIngredients.php
-->
<!--this php file is adding ingredients to the table and updates when ingredients are the same. Also, there is an option
to go back to the main menu -->
<?php
// to get data stored in a session, you must let the browser know to start a session
session_start();
// take data values from the session variables and store them
$host = $_SESSION["host"];
$user = $_SESSION["user"];
$pass = $_SESSION["pass"];
$dbName = $user;
// build the connection ...
$conn = mysqli_connect($host, $user, $pass, $dbName);
// Get data from user
$ingredients = $_POST["ingredient"];
$quantities = $_POST["quantity"];
// find all matching ingredient data
$queryString = "select Ingredient, Quantity from Inventory ".
" where Ingredient =\"$ingredients\"";
$status = mysqli_query($conn, $queryString);
// try and insert request
$queryString = "INSERT INTO Inventory VALUES (\"$ingredients\", $quantities)";
$status = mysqli_query($conn, $queryString);
if (!$status)
{
//update the inventory table and set the quantity to quantity plus the new quantities where ingredients mach
$queryString = " update Inventory set Quantity = Quantity+ $quantities where Ingredient =\"$ingredients\"";
$status = mysqli_query($conn, $queryString);
}
// close the connection (to be safe)
mysqli_close($conn);
// link to go back to the main menu
echo "<a href=MainMenu.html>Go back to the main menu</a>";
?>