-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertorder.php
More file actions
104 lines (84 loc) · 2.45 KB
/
insertorder.php
File metadata and controls
104 lines (84 loc) · 2.45 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
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
<?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';
}
//Select all rows from menucard
$sqlme = "SELECT * FROM menucard";
$result1 = $conn->query($sqlme);
$sqlord = "SELECT * FROM orders where username='$uname' ORDER BY id DESC LIMIT 5";
$resultord = $conn->query($sqlord);
//
$sqlmen = "SELECT * FROM customers where name = '$uname'";
$result3 = $conn->query($sqlmen);
while($row = $result3->fetch_assoc()){
$userid = $row['id'];
}
//Insert the food items which is not equal to zero
for($i=0;$i<6;$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);
while($row = $result1->fetch_assoc())
{
if($f == $row['food'])
{
$chkpt = $row['id'];
$time = $row['time'];
$machine = $row['machine'];
}
}
while($row = $resultord->fetch_assoc())
{
if($f == $row['food'])
{
$quantity = $row['quantity'];
}
}
if($machine == 1)
$tablemach = 'idmaster';
else if($machine == 2)
$tablemach = 'chmaster';
else if($machine == 3)
$tablemach = 'ffmaster';
$time = $time * $quantity;
$sql2 = "INSERT INTO $tablemach (userid, food, time) VALUES ('$userid', '$f', '$time')";
$result2 = $conn->query($sql2);
}
}
//Token
$resulttoke=mysql_query("SELECT count(*) as total from tokengiver");
$countserve=mysql_fetch_assoc($resulttoke);
$lasttoken = $countserve['total'];
$lasttoken = $lasttoken++;
$sql4 = "INSERT INTO tokengiver (username, token) VALUES ('$uname','$lasttoken')";
$result4 = $conn->query($sql4);
// Redirect after inserting into Database...
//echo '<script type="text/javascript">
// window.location = "addorder.php"
// </script>';
echo "added".$time;
?>