forked from miznokruge/cyber-arief
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindah.php
69 lines (54 loc) · 1.09 KB
/
indah.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
<!DOCTYPE html>
<html>
<head>
<title>gue</title>
</head>
<body>
<?php
session_start();
include 'koneksi.php';
class item{
var $id;
var $nama;
var $harga;
var $quantity;
}
if (isset($_GET['id'])){
$result = mysqli_query($koneksi, 'select * from product where id_bj'.$_GET['id']);
$product = mysqli_fetch_object($result);
$item = new item();
$item->id=$product->id_bj;
$item->nama=$product->nama;
$item->harga=$product->harga;
$item->quantity=1;
// check product is ecisting in cart
$cart = unserialize(serialize($_SESSION['cart']));
$index = -1;
for ($i=0; $i <count($cart) ; $i++)
if ($cart[$i]->id==$_GET['id']) {
$index = $i;
break;
}
if ($index ==-1) {
$_SESSION['cart'][] =$item;
}
else
{
$cart[$index]->quantity++;
$_SESSION['cart'] = $cart;
}
}
// delete product in cart
if (isset($_GET['index'])) {
$cart = unserialize(serialize($_SESSION)['cart']);
unset($cart[$_GET['index']]);
$cart = array_values($cart);
$_SESSION['cart'];
}
?>
<div class="container">
<div class="page-header" align="center"><h1></h1>
</div>
</div>
</body>
</html>