-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorderproduct.php
146 lines (104 loc) · 3.36 KB
/
orderproduct.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
<?php
session_start();
include_once 'controller/product.php';
$_Product = new Product();
$user_id = $_SESSION['user_id'];
$date = date("Y/m/d");
$connection = mysqli_connect("localhost","root","","hstore");
function generateOrderNo($user_id,$date)
{
$connection = mysqli_connect("localhost","root","","hstore");
$query = "INSERT INTO orders(o_date, user_id) VALUES ('$date',$user_id);";
$result = mysqli_query($connection, $query);
if ($result)
//success
echo "successful";
else
{
die("Database query not working. " . mysqli_error($connection));
}
return mysqli_insert_id($connection);
}
if(isset($_POST['order'])){
foreach($_SESSION['cart'] as $id => $value) {
$order_id = generateOrderNo($user_id,$date);
$amount = $_SESSION['cart'][$id]['quantity'];
$query = "INSERT INTO product_order(order_no,p_id, o_amount) VALUES ('$order_id','$id','$amount');";
$result = mysqli_query($connection, $query);
}
$_Product->clearCart();
header( "url=orderproduct.php" );
}
if(isset($_GET['cart'])){
if($_GET['cart']=='reset'){
$_Product->clearCart();
header( "url=orderproduct.php" );
}
}
if(isset($_GET['page'])){
$pages=array("products", "cart");
if(in_array($_GET['page'], $pages)) {
$_page=$_GET['page'];
}else{
$_page="products";
}
}else{
$_GET['cart']='';
$_page="products";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="resources/css/reset.css" />
<link rel="stylesheet" href="resources/css/style.css" />
<link rel="stylesheet" href="resources/css/master.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="resources/js/script.js" charset="utf-8"></script>
<script src="resources/js/jquery.min.js"></script>
<title>Order Product</title>
</head>
<body>
<header>
<?php include_once 'template/header.php'; ?>
</header>
<div id="container">
<div id="main">
<?php require($_page.".php"); ?>
</div><!--end of main-->
<div id="sidebar">
<h1>Cart</h1>
<?php
if(isset($_SESSION['cart'])){
$connection = mysqli_connect("localhost","root","","hstore");
$sql="SELECT products.id as id_product, p_name, p_amount,specs, man_name FROM products
inner join manufecturer on products.man_id = manufecturer.id WHERE products.id IN (";
foreach($_SESSION['cart'] as $id => $value) {
$sql.=$id.",";
}
$sql=substr($sql, 0, -1).") ORDER BY p_name ASC";
$result = mysqli_query($connection, $sql);
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
$cart_txt = $row['p_name'].' '.'-> '.$row['man_name'];
?>
<p><?php echo $cart_txt ?> x <?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?></p>
<?php
}
?>
<hr />
<a href="orderproduct.php?page=cart">Go to cart</a> <br>
<a href="orderproduct.php?cart=reset" class="right">Reset cart</a>
<?php
}else{
echo "<p>Your Cart is empty. Please add some products.</p>";
}
?>
</div><!--end of sidebar-->
<form class="right" action="" method="post">
<input type="submit" name="order" value="Order Now">
</form>
</div><!--end container-->
</body>
</html>
<?php include_once 'template/footer.php'; ?>