-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_from_cart.php
More file actions
executable file
·30 lines (29 loc) · 1002 Bytes
/
remove_from_cart.php
File metadata and controls
executable file
·30 lines (29 loc) · 1002 Bytes
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
<?php
/**
* Created by PhpStorm.
* User: Daniel
* Date: 5/26/2016
* Time: 1:45 PM
* @formatter:off
*/
include ('includes/initialize.php');
if (LOGGED_IN)
{
$results = mysqli_query($conn,"SELECT * FROM cart WHERE id_user=".$_SESSION['userID']." AND open=1 AND id=".$_GET['id_cart'].";");
if ($results)
{
$cart = mysqli_fetch_array($results);
$total = floatval($cart['total']);
$results = mysqli_query($conn,"SELECT * FROM cart_products WHERE id_cart=".$_GET['id_cart']." AND id_product=".$_GET['id_product'].";");
while ($row = mysqli_fetch_array($results))
{
$res = mysqli_query($conn,"SELECT * FROM products WHERE id=".$row['id_product']);
$p = mysqli_fetch_array($res);
$total -= floatval($p['price']);
}
echo $total;
mysqli_query($conn, "UPDATE cart SET total=".$total." WHERE id=".$_GET['id_cart']);
mysqli_query($conn, "DELETE FROM cart_products WHERE id_cart=".$_GET['id_cart']." AND id_product=".$_GET['id_product']);
}
}
header("Location: cart.php");