-
Notifications
You must be signed in to change notification settings - Fork 0
/
wishlist.php
114 lines (85 loc) · 3.71 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
@include 'config.php';
session_start();
$user_id = $_SESSION['user_id'];
if(!isset($user_id)){
header('location:login.php');
}
if(isset($_POST['add_to_cart'])){
$product_id = $_POST['product_id'];
$product_name = $_POST['product_name'];
$product_price = $_POST['product_price'];
$product_image = $_POST['product_image'];
$product_quantity = 1;
$check_cart_numbers = mysqli_query($conn, "SELECT * FROM `cart` WHERE name = '$product_name' AND user_id = '$user_id'") or die('query failed');
if(mysqli_num_rows($check_cart_numbers) > 0){
$message[] = 'already added to cart';
}else{
$check_wishlist_numbers = mysqli_query($conn, "SELECT * FROM `wishlist` WHERE name = '$product_name' AND user_id = '$user_id'") or die('query failed');
if(mysqli_num_rows($check_wishlist_numbers) > 0){
mysqli_query($conn, "DELETE FROM `wishlist` WHERE name = '$product_name' AND user_id = '$user_id'") or die('query failed');
}
mysqli_query($conn, "INSERT INTO `cart`(user_id, pid, name, price, quantity, image) VALUES('$user_id', '$product_id', '$product_name', '$product_price', '$product_quantity', '$product_image')") or die('query failed');
$message[] = 'product added to cart';
}
}
if(isset($_GET['delete'])){
$delete_id = $_GET['delete'];
mysqli_query($conn, "DELETE FROM `wishlist` WHERE id = '$delete_id'") or die('query failed');
header('location:wishlist.php');
}
if(isset($_GET['delete_all'])){
mysqli_query($conn, "DELETE FROM `wishlist` WHERE user_id = '$user_id'") or die('query failed');
header('location:wishlist.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wishlist</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php @include 'header.php'; ?>
<section class="heading">
<h3>❤</h3>
</section>
<section class="wishlist">
<div class="box-container">
<?php
$grand_total = 0;
$select_wishlist = mysqli_query($conn, "SELECT * FROM `wishlist` WHERE user_id = '$user_id'") or die('query failed');
if(mysqli_num_rows($select_wishlist) > 0){
while($fetch_wishlist = mysqli_fetch_assoc($select_wishlist)){
?>
<form action="" method="POST" class="box">
<img src="uploaded_img/<?php echo $fetch_wishlist['image']; ?>" alt="" class="image">
<div class="name"><?php echo $fetch_wishlist['name']; ?></div>
<div class="price">Rs<?php echo $fetch_wishlist['price']; ?>.00</div>
<input type="hidden" name="product_id" value="<?php echo $fetch_wishlist['pid']; ?>">
<input type="hidden" name="product_name" value="<?php echo $fetch_wishlist['name']; ?>">
<input type="hidden" name="product_price" value="<?php echo $fetch_wishlist['price']; ?>">
<input type="hidden" name="product_image" value="<?php echo $fetch_wishlist['image']; ?>">
<input type="submit" value="add to cart" name="add_to_cart" class="btn">
</form>
<?php
$grand_total += $fetch_wishlist['price'];
}
}else{
echo '<p class="empty">your wishlist is empty</p>';
}
?>
</div>
<div class="wishlist-total">
<p>Total : <span>Rs.<?php echo $grand_total; ?>.00</span></p>
<a href="shop.php" class="option-btn">Continue</a>
<a href="wishlist.php?delete_all" class="delete-btn <?php echo ($grand_total > 1)?'':'disabled' ?>" onclick="return confirm('delete all from wishlist?');">Delete all</a>
</div>
</section>
<?php @include 'footer.php'; ?>
<script src="js/script.js"></script>
</body>
</html>