-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_cart.php
More file actions
85 lines (66 loc) · 2.45 KB
/
add_cart.php
File metadata and controls
85 lines (66 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
<?php
// Set the page title and include the HTML header:
session_start(); // Start the session.
$page_title = 'Add to Cart';
include ('includes/header.html');
echo '<div id="content">
<div class="container">
<div class="inside">
<!-- box begin -->
<div class="box alt">
<div class="left-top-corner">
<div class="right-top-corner">
<div class="border-top"></div>
</div>
</div>
<div class="border-left">
<div class="border-right">
<div class="inner">
<div class="wrapper">';
if (isset ($_GET['pid']) && is_numeric($_GET['pid']) ) { // Check for a print ID.
$pid = (int) $_GET['pid'];
// Check if the cart already contains one of these prints;
// If so, increment the quantity:
if (isset($_SESSION['cart'][$pid])) {
$_SESSION['cart'][$pid]['quantity']++; // Add another.
// Display a message.
echo '<p>Another of the food has been added to your order.</p>';
} else { // New product to the cart.
// Get the print's price from the database:
require_once ('../mysqli_connect.php');
$q = "SELECT price FROM prints WHERE prints.print_id = $pid";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) == 1) { // Valid print ID.
// Fetch the information.
list($price) = mysqli_fetch_array ($r, MYSQLI_NUM);
// Add to the cart:
$_SESSION['cart'][$pid] = array ('quantity' => 1, 'price' => $price);
// Display a message:
echo '<p>Your order have been submitted.</p>';
} else { // Not a valid print ID.
echo '<div align="center">This page has been accessed in error!</div>';
}
mysqli_close($dbc);
} // End of isset($_SESSION['cart'][$pid] conditional.
} else { // No print ID.
echo '<div align="center">This page has been accessed in error!</div>';
}
echo ' <dl class="special fright">
</div>
</div>
</div>
</div>
<div class="left-bot-corner">
<div class="right-bot-corner">
<div class="border-bot"></div>
</div>
</div>
</div>
<!-- box end -->
<!--Recent articles list ends -->
</div>
</div>
</div>
';
include ('includes/footer.html');
?>