-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertorder.php
More file actions
53 lines (40 loc) · 1.17 KB
/
Copy pathinsertorder.php
File metadata and controls
53 lines (40 loc) · 1.17 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
<?php
session_start();
if(!isset($_SESSION["uname"])) {
echo '<script type="text/javascript">
window.location = "login.php"
</script>';
}
//Food items and quantity got as a single GET request from addorder.php
$food=$_GET['food'];
$quantity=$_GET['quantity'];
$uname=$_SESSION["uname"];
//Splitting food items and quantity based on delimiter "space" got from $quantity and $food...
$foodpieces = explode(" ", $food);
$quantitypieces = explode(" ", $quantity);
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "cipproject";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
$errors='2';
}
//Insert the food items which is not equal to zero
for($i=0;$i<4;$i++)
{
if($quantitypieces[$i]!=0)
{
$f=$foodpieces[$i];
$q=$quantitypieces[$i];
$sql = "INSERT INTO orders (username, food, quantity) VALUES ('$uname', '$f', '$q')";
$result = $conn->query($sql);
}
}
// Redirect after inserting into Database...
echo '<script type="text/javascript">
window.location = "addorder.php"
</script>';
?>