-
Notifications
You must be signed in to change notification settings - Fork 1
/
u_cart.php
59 lines (39 loc) · 1.43 KB
/
u_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
<?php
session_start();
if(isset($_SESSION['u_name'])){
$us_name= $_SESSION['u_name'] ;
require_once "connect.php";
$user_name = $_SESSION['u_name'];
$p_id = $_POST['p_id'];
$qty = 1;
$price = $_POST['price'];
//Insert Into Cart, Created on 29-03-2018, Prabhat Chandra
$conn->query("REPLACE INTO `u_cart` VALUES( $p_id, $qty, $price, '$user_name' )") or die(mysqli_error($conn));
//$conn->query("UPDATE `u_cart` SET `u_name` = '$u_name', `u_qty` = $qty , `u_price` = $price
// WHERE p_id = $id ")
// or die(mysqli_error($conn));
//Cart Calculation, Created on 30-03-2018, Prabhat Chandra
$sql = $conn->query("SELECT p_id, user_name, SUM(u_price) AS t_price
FROM u_cart
GROUP BY user_name ;
;")
or die(mysqli_error($conn)) ;
while($min = $sql->fetch_array()){
$id = $min['p_id'];
$cus_name = $min['user_name'];
$totalprice = $min['t_price'];
//echo $t_price;
$conn->query("REPLACE INTO `cart_t` VALUES( '$cus_name', '$totalprice' )") or die(mysqli_error($conn));
}
//Redirection while checking query error, 10-04-2018, Prabhat Chandra
if (!$sql) {
header('Location: error.php', TRUE, 303);
die('Invalid query: ' . mysql_error());
} else {
header('Location: qty_total.php', TRUE, 303);
die('Success');
}
} else {
header('Location: login.php');
}
?>