-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
119 lines (112 loc) · 3.59 KB
/
cart.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
<?php
session_start();
require_once 'component.php';
if(isset($_POST["remove"])){
if($_GET["action"] == "remove"){
foreach($_SESSION["cart"] as $key => $value){
if($value["games_id"] == $_GET["id"]){
unset($_SESSION["cart"][$key]);
echo "<script>alert('Game removed from cart');</script>";
echo "<script>window.location = 'cart.php';</script";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GameVerse - Cart</title>
<link rel="stylesheet" href="cart.css">
<!-- Link your CSS file or add styles directly here for the cart page -->
</head>
<body>
<header>
<h1>Shopping cart</h1>
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<!-- <li><a href="#games">Games</a></li> -->
<?php
if(isset($_SESSION["username"])){
// if(isset($_SESSION["cart"])){
// $count = count($_SESSION["cart"]);
// echo "<li><a href='cart.php'>Cart $count</a></li>";
// }
// else{
// echo "<li><a href='cart.php'>Cart 0</a></li>";
// }
echo "<li><a href='profile.php'>Profile</a></li>
<li><a href='logout.php'>Logout</a></li>";
}
else{
echo "<li><a href='login.php'>Login</a></li>
<li><a href='signup.php'>Sign Up</a></li>";
}
?>
</ul>
</nav>
</header>
<main>
<!-- <section id="cart"> -->
<!-- <h2>Your Shopping Cart</h2> -->
<!-- <div class="cart-items"> -->
<!-- Cart items dynamically generated based on user selections -->
<!-- Example cart item structure -->
<!-- <div class="cart-item">
<img src="https://cdn.akamai.steamstatic.com/steam/apps/1551360/header.jpg?t=1699624973" alt="Game 1">
<h3>Forza Horizon 5</h3>
<p>Description: Your Ultimate Horizon Adventure awaits!...</p>
<h1>Rs 3499.00</h1>
<button>Remove</button>
</div> -->
<!-- Repeat this structure for each item in the cart -->
<!-- </div>
<div class="cart-total">
<h3>Total:</h3> -->
<!-- Display the total price of all items in the cart -->
<!-- <h1>Rs Total Amount</h1>
</div>
<div class="checkout">
<button>Proceed to Checkout</button>
</div>
</section> -->
<section class="cart">
<h2>Order Details</h2>
<div class="orders">
<?php
require_once 'dbconnection.php';
$total = 0;
if(isset($_SESSION["cart"])){
$games_id = array_column($_SESSION["cart"], "games_id");
$sql = "SELECT * FROM games";
$resultData = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($resultData)){
foreach($games_id as $id){
if($row["games_id"] == $id){
cartItem($row["games_name"], $row["games_publisher"], $row["games_genre"], $row["games_price"], $row["games_id"]);
$total += (int)$row["games_price"];
}
}
}
mysqli_close($conn);
}
else{
echo "<h5>Cart Empty</h5>";
}
?>
<form action="action_cart.php" method="post">
<div class="cart-item">
<h3>Total Amount: <?php echo $total; ?></h3>
<button type="submit" name="buy">Buy</button>
</div>
</form>
<!-- More orders -->
</div>
</section>
</main>
<!-- <footer>
</footer> -->
</body>
</html>