source: Wishlist.php

Last change on this file was e3d4e0a, checked in by Vlado 222039 <vlado.popovski@…>, 6 days ago

Upload project files

  • Property mode set to 100644
File size: 5.6 KB
Line 
1<?php
2
3 session_start();
4 if(!isset($_SESSION['user_ID'])) {
5 header("Location: ./Log In.php");
6 }
7 require "./connect.php";
8
9 if(isset($_POST['submit']) && isset($_POST['product_id'])) {
10
11 if($_POST['submit'] == 'Remove') {
12 $res = mysqli_query($conn, "DELETE FROM wishlist WHERE user_id = {$_SESSION['user_ID']} AND product_id = {$_POST['product_id']};");
13 }
14 }
15
16 function get_wishlist_products() {
17 global $conn;
18 $products = [];
19 $res = mysqli_query($conn, "SELECT products.product_id, products.name, products.category, products.price, products.discount, products.image1 FROM products INNER JOIN wishlist ON
20 products.product_id = wishlist.product_id WHERE user_id = {$_SESSION['user_ID']};");
21
22 foreach($res as $row) {
23 $products[] = $row;
24 }
25
26 return $products;
27 }
28
29 $product_list = get_wishlist_products();
30?>
31
32<!DOCTYPE html>
33<html lang="en">
34<head>
35 <meta charset="UTF-8">
36 <meta name="viewport" content="width=device-width, initial-scale=1.0">
37 <title>Wishlist</title>
38 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
39 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css">
40 <link rel="stylesheet" href="https://unpkg.com/boxicons@latest/css/boxicons.min.css">
41 <link rel="stylesheet" href="/CSS/Cart.css">
42 <link rel="stylesheet" href="/CSS/Header.css">
43</head>
44<body>
45
46 <?php include './components/Header.html' ?>
47
48 <section>
49 <div class="pagination">
50 <p>Home > Wishlist</p>
51 </div>
52 <div class="container px-4 py-5 mx-auto">
53 <div class="row d-flex justify-content-center">
54 <?php if(count($product_list) >= 1) {?>
55 <div class="col-5">
56 <h4 class="heading">Wishlist</h4>
57 </div>
58 <div class="col-7">
59 <div class="row text-right">
60 <div class="col-4">
61 <h6 class="mt-2">Price</h6>
62 </div>
63 </div>
64 </div>
65 <?php } ?>
66 </div>
67
68 <?php
69
70 foreach($product_list as $product) {
71 ?>
72 <div class="row d-flex justify-content-center border-top">
73 <div class="col-5">
74 <div class="row d-flex">
75 <div class="book">
76 <img src="<?php
77 if($product['image1'] != null) {
78 $first_image = basename(strrchr($product['image1'], '/'));
79 $first_image = str_replace(array("'"), '', $first_image);
80 echo "./UPLOADED_IMAGES/".$first_image;
81 }
82 ?>" class="book-img">
83 </div>
84 <div class="my-auto flex-column d-flex pad-left">
85 <h6 class="mob-text"><?php echo $product['name'] ?></h6>
86 <p class="mob-text"><?php echo $product['category'] ?></p>
87 </div>
88 </div>
89 </div>
90 <div class="my-auto col-7">
91 <div class="row text-right">
92 <div class="col-4">
93 <h6 class="mob-text">
94 <?php
95 $discountAmount = $product['price'] * ($product['discount'] / 100);
96 echo "$".($product['price'] - $discountAmount);
97 ?>
98 </h6>
99 </div>
100 <div class="col-4">
101 <form action="./Products.php" method="GET">
102 <input type="hidden" name="product_id" value="<?php echo $product['product_id'] ?>">
103 <input class="btn btn-sm btn-success" type="submit" name="submit" value="add-to-cart">
104 </form>
105 <form action="./Wishlist.php" method="POST">
106 <input type="hidden" name="product_id" value="<?php echo $product['product_id'] ?>">
107 <input class="btn btn-sm btn-danger" type="submit" name="submit" value="Remove">
108 </form>
109 </div>
110 </div>
111 </div>
112 </div>
113 <?php
114 }
115
116 if(count($product_list) <= 0) {
117 echo '<p>Your wish list is empty!</p>';
118 }
119 ?>
120 </div>
121 </section>
122
123 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
124 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
125</body>
126</html>
Note: See TracBrowser for help on using the repository browser.