-
Notifications
You must be signed in to change notification settings - Fork 0
/
addCart.php
57 lines (44 loc) · 1.45 KB
/
addCart.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
<?php
/**
* Created by PhpStorm.
* User: msbomrel
* Date: 11/29/16
* Time: 9:49 AM
*/
session_start();
include ('include/connect.php');
if (isset($_SESSION['user'])) {
if(isset($_POST['submit'])) {
$user = $_SESSION['user'];
$sid = session_id();
$pid = $_GET['id'];
$qty = $_POST['qty'];
$checkproduct = "select * from cost where username= '$user' && product_id='$pid'";
$result = mysqli_query($conn, $checkproduct);
while ($row = mysqli_fetch_assoc($result)) {
$pro = $row['product_id'];
$old_qty = $row['qty'];
}
if ($pro == $pid) {
$finalqty = $old_qty + $qty;
mysqli_query($conn, "update cost set qty ='$finalqty' WHERE username ='$user' && product_id='$pid'");
echo "<script>window.location = 'viewCart.php';</script>";
}
else {
$sql = "insert into cost (username,session_id,product_id,qty) VALUES ('$user','$sid','$pid','$qty')";
$res = mysqli_query($conn, $sql) or die("dbms error");
if ($res) {
echo "<script>window.location = 'viewCart.php';</script>";
}
}
}
} else
{
?>
<script>
alert('You Are Not Logged In !! You need to login to add items in the Cart...');
alert(window.location = 'login.php');
</script>
<?php
}
?>