-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_cart.php
46 lines (45 loc) · 1.95 KB
/
action_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
<?php
session_start();
if(isset($_POST["buy"])){
if(isset($_SESSION["cart"]) && count($_SESSION["cart"]) != 0){
require_once 'dbconnection.php';
require_once 'component.php';
$total = 0;
$games_id = array_column($_SESSION["cart"], "games_id");
$sql1 = "SELECT * FROM games";
$resultData1 = mysqli_query($conn, $sql1);
while($row = mysqli_fetch_assoc($resultData1)){
foreach($games_id as $id){
if($row["games_id"] == $id){
$total += (int)$row["games_price"];
}
}
}
$games_id = array_column($_SESSION["cart"], "games_id");
$resultData1 = mysqli_query($conn, $sql1);
$userid = (int)$_SESSION["id"];
$billid = (int)$_SESSION["billid"] + 1;
$_SESSION["billid"] = $billid;
$date = date("jS \of F Y");
while($row = mysqli_fetch_assoc($resultData1)){
foreach($games_id as $id){
if($row["games_id"] == $id){
$gameid = (int)$row["games_id"];
$sql = "INSERT INTO bill (bill_id, bill_userid, bill_gameid, bill_date, bill_amount) VALUES ($billid, $userid, $gameid, '$date', '$total');";
mysqli_query($conn, $sql);
}
}
}
foreach($_SESSION["cart"] as $key => $value){
unset($_SESSION["cart"][$key]);
echo "<script>window.location = 'index.php';</script>";
}
mysqli_close($conn);
echo "<script>alert('Payment Successful...');</script>";
echo "<script>window.location.href = 'index.php';</script>";
}
else{
echo "<script>alert('cart is empty');</script>";
echo "<script>window.location.href = 'index.php';</script>";
}
}