-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddtocart.php
74 lines (58 loc) · 2.18 KB
/
addtocart.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
<?php
include_once('include/connection.php');
if(isset($_POST['submit'])) {
session_start();
$sessionid = session_id();
$productaantal = $_POST['aantal'];
$productid = $_GET['productid'];
$datum = date("Y-m-d");
$STHwm = $DBH->prepare('SELECT * FROM tbltijdelijkewinkelwagen WHERE sessionid = :sessionid AND productid = :productid');
$STHwm->bindParam(':productid',$productid);
$STHwm->bindParam(':sessionid',$sessionid);
$STHwm->execute();
$STHwm->setFetchMode(PDO::FETCH_OBJ);
while ($row = $STHwm->fetch()) {
$oudaantal = $row->aantal;
$nieuwaantal = $oudaantal + $productaantal;
}
$aantal = $STHwm->rowCount();
if ($aantal > 0){
$STH = $DBH->prepare('UPDATE tbltijdelijkewinkelwagen SET aantal = :aantal WHERE sessionid = :sessionid AND productid = :productid ;');
$STH->bindParam(':productid',$productid);
$STH->bindParam(':sessionid',$sessionid);
$STH->bindParam(':aantal',$nieuwaantal);
$STH->execute();
header('location:prod.php');
exit;
} else {
$STH = $DBH->prepare('SELECT * FROM tblproducten WHERE productid = :productid');
$STH->bindParam(':productid',$productid);
$STH->execute();
$STH->setFetchMode(PDO::FETCH_OBJ);
while ($row = $STH->fetch()) {
$prijs = $row->prijs;
$promotie = $row->promotie;
if ($promotie > 0){
$prijs = $promotie;
} else {
$prijs = $prijs;
}
}
$STH = $DBH->prepare('INSERT INTO tbltijdelijkewinkelwagen (sessionid, productid, aantal, prijs, datum)VALUES(:sessionid,:productid,:aantal,:prijs, :datum)');
$STH->bindParam(':sessionid', $sessionid);
$STH->bindParam(':productid', $productid);
$STH->bindParam(':aantal', $productaantal);
$STH->bindParam(':prijs', $prijs);
$STH->bindParam(':datum', $datum);
$STH->execute();
echo $productid . '<br>';
echo $aantal . '<br>';
echo $datum . '<br>';
echo $sessionid . '<br>';
header('location:prod.php');
exit();
}
} else {
header('location:prod.php');
}
?>