-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcart.php
91 lines (54 loc) · 2.02 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
<?php
error_reporting(0);
session_start();
$mail=$_SESSION['alogin'];
//$pname=$_SESSION['name'];
$id=$_SESSION['pid'];
?>
<?php
$con=mysqli_connect("localhost","root","","organic_shop_db")or die ("Couldnt connect");
$cart_total=0;
$viewbrand1="Select * from tbl_product where pid=$id ";
//$viewbrand1="Select * from tbl_product where name=$pname ORDER BY name ASC";
$d_seller_brand1=mysqli_query($con,$viewbrand1);
//$viewbrand="Select * from cart inner join tbl_product on cart.pid=tbl_product.pid inner join tbl_registration on tbl_registration.email=cart.email where cart.pid=8 and cart.email='[email protected]'";
$viewbrand="Select * from cart inner join tbl_product on cart.pid=tbl_product.pid inner join tbl_registration on tbl_registration.email=cart.email where cart.pid=$id and cart.email='$mail'";
//$viewbrand="Select * from tbl_product where name=$pname ORDER BY name ASC";
$d_seller_brand=mysqli_query($con,$viewbrand);
$countp=mysqli_num_rows($d_seller_brand);
$rowp=mysqli_fetch_array($d_seller_brand1);
$rd=$rowp['rid'];
//$product_category=$rowp['product_category_id'];
$price=$rowp['price'];
$cart_item_qty=$_POST['qt'];
$cart_total=$cart_item_qty * $price;
$old_stock=$rowp['qunty'];
$flag=0;
if($countp>=1)
{
echo "<script type='text/javascript'>
alert(' Item already added to cart');
window.location='cart_view.php';
</script>";
}
else
{
$q_ins1="INSERT INTO `cart` (`email`, `pid`, `cart_qunty`, `amount`,old_stock) VALUES ('$mail', $id, '$cart_item_qty', '$cart_total','$old_stock')";
//insert into cart(rid,product_category_id,pid,cart_qunty,amount)values($rd,$product_category,$id,$cart_item_qty,$cart_total)";
$ins=mysqli_query($con,$q_ins1);
if($ins)
{
echo "<script type='text/javascript'>
alert('Item added to cart successfully');
window.location='cart_view.php';
</script>";
}
else
{
echo "<script type='text/javascript'>
alert('Failed');
window.location='cart_view.php';
</script>";
}
}
?>