-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwishlist.php
91 lines (83 loc) · 3.14 KB
/
wishlist.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>The Rubicon Express</title>
</head>
<body>
<?php
require_once('menu.php');
?>
<div class="container" style="width:60%; padding-bottom: 30px">
<h2 align="center">My wishlist</h2>
<br>
<?php
$query2 = "SELECT * FROM wishlist ORDER BY wishlist_id";
$result2 = mysqli_query($connect, $query2); ?>
<form method="post" id="productsForm">
<?php
if (mysqli_num_rows($result2) > 0):
while ($row2 = mysqli_fetch_array($result2)):
$product_id = $row2['product_id'];
$query = "SELECT * FROM product WHERE product_id = $product_id";
$result = mysqli_query($connect, $query);
$row = mysqli_fetch_array($result);
?>
<div class="col-md-4" style="display: none;">
<div style="border: 1px solid #eaeaec; margin: -1px 19px 3px -1px; box-shadow: 0 1px 15px rgba(0,0,0,0.05); padding:10px;"
align="center">
<img src="<?php echo $row["image"]; ?>" class="img-responsive" style="max-height: 130px;">
<h5 class="text-info"><?php echo $row["name"]; ?></h5>
<h5 class="text-danger">฿<?php echo $row["price"]; ?></h5>
<button name="addButton" style="margin-top:5px;" class="btn btn-success"
value="<?php echo $row["product_id"]; ?>"> Add to Cart
</button>
<button name="removeButton" style="margin-top:5px;" class="btn btn-danger"
value="<?php echo $row["product_id"]; ?>"> Remove
</button>
</div>
</div>
<?php
endwhile;
else:
echo "<i><h3 align='center'>Your wishlist is empty.</h3></i>";
endif;
?>
</form>
</div>
<?php require_once('footer.php') ?>
</body>
</html>
<script>
var productID, btnString = 'cart';
$(document).ready(function () {
$(".col-md-4").fadeIn("slow");
initialLoad();
});
function initialLoad() {
$('button[name="removeButton"]').click(function () {
productID = $(this).val();
btnString = 'remove';
});
$('button[name="addButton"]').click(function () {
productID = $(this).val();
btnString = 'cart';
});
// Attach a submit handler to the form
$("#productsForm").submit(function (event) {
// Stop form from submitting normally
event.preventDefault();
var posting;
if (btnString === 'cart')
posting = $.post("php-action/add-cart.php", {hidden_id: productID});
else
posting = $.post("php-action/remove-wishlist.php", {hidden_id: productID});
// Put the results in a div
posting.done(function (data) {
swal('Success!', data, 'success').then(function () {
location.reload();
});
});
});
}
</script>