-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubmitOrder.php
52 lines (36 loc) · 1.09 KB
/
submitOrder.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
<?php $dir = ""; include($dir . "header.php"); ?>
<?php
echo "alert('submitting')";
$servername = "localhost";
$username = "root";
$password = "admin";
$dbname = "cscomp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$cost = 0;
$items = "none|";
if (isset($_POST["item"])) {
$items ="";
$name = $_POST["item"];
foreach ($name as $item){
$items .=str_replace('_', ' ', $item)."|";
$result = $conn->query("Select * from items where name='".$item."'");
while($row = $result->fetch_assoc()) {
$cost += $row['price'];
}
}
}
//gets rid of the last '|'
$items = substr($items,0,-1);
$sql = "Insert into orders(itemsName, cost, team_user, active) values ('".$items."','".$cost."','".$_SESSION['username']."','yes')";
$result = $conn->query($sql);
$conn->close();
ob_start();
header('Location: '.'vieworders.php');
ob_end_flush();
die();
?>