diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-05-09 14:50:10 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-05-09 14:50:10 +0200 |
commit | 07d9bcf6b55a7aa866397def09c300347d9c88ea (patch) | |
tree | b7734f271aba677228300eebd732e41302692c84 /public | |
parent | 6d5c72f908e8f7c1c2b0defa696aad43c55fc1ba (diff) |
WIP show cart count
Diffstat (limited to 'public')
-rw-r--r-- | public/cart.php | 56 | ||||
-rw-r--r-- | public/db.php | 1 | ||||
-rw-r--r-- | public/index.php | 2 | ||||
-rw-r--r-- | public/product.php | 3 | ||||
-rw-r--r-- | public/products.php | 2 |
5 files changed, 51 insertions, 13 deletions
diff --git a/public/cart.php b/public/cart.php index e1c7907..f953880 100644 --- a/public/cart.php +++ b/public/cart.php @@ -1,6 +1,40 @@ <!DOCTYPE html> +<?php require "../lib/db.php" ?> <?php require "../lib/login.php" ?> <?php if_logged_in(false, "/login.php", true) ?> +<?php +do { + if ($_SERVER['REQUEST_METHOD'] !== 'POST') break; + if (!$_POST['product_id']) break; + + // TODO: add product to cart + // $statement = $cursor->prepare("select id, image, price, name, description from webs.product where id = ?"); + // $statement->bind_param("i", $_GET['id']); + // if (!$statement->execute()) refuse(); + // $res = $statement->get_result(); + // if (!mysqli_num_rows($res)) refuse(); + // $product = $res->fetch_object(); + + + // if all guards passed, successful login occurred + cookie_redir($_POST['username'], $_POST['password']); +} while (false); +?> +<?php +function item_template($item) { + $image_path = $item->image ? "/img/product/$item->id-thumb.jpg" : "/img/placeholder.png"; + echo <<<"EOF" + <div class="product"> + <img src="$image_path" alt="productafbeelding"> + <span class="name">$item->name</span> + <label for="$item->id-count">hoeveelheid:</label> + <input type="number" value="$item->count" min="1" max="20" id="$item->id-count"> + <button id="$item->id-delete">weghalen</button> + <span class="price">$item->price</span> + </div> +EOF; +} +?> <html> <head> <?php include 'head.php' ?> @@ -10,16 +44,20 @@ <body> <?php include 'navbar.php' ?> <div class="main limwidth"> - <h2>dingen in je mand</h2> + <h2>dingen in de mand van <?php echo $username ?></h2> <div class="products"> - <div class="product"> - <img src="img/placeholder.png" alt="productafbeelding"> - <span class="name">courgette</span> - <label for="123-count">hoeveelheid:</label> - <input type="number" value="1" min="1" max="20" id="123-count"> - <button id="123-delete">weghalen</button> - <span class="price">3,45</span> - </div> + <?php do { + global $username; + $statement = $cursor->prepare("select product.id, product.name, product.price, product.image, cart.count from cart join customer on customer.id = cart.customer join product on product.id = cart.product where customer.name = ?"); + $statement->bind_param("s", $username); + if (!$statement->execute()) break; + $res = $statement->get_result(); + if (!mysqli_num_rows($res)) { + echo "mandje leeg"; + break; + } + while ($product = $res->fetch_object()) item_template($product); + } while (false); ?> </div> </div> <?php include 'footer.php' ?> diff --git a/public/db.php b/public/db.php deleted file mode 100644 index 6d158b7..0000000 --- a/public/db.php +++ /dev/null @@ -1 +0,0 @@ -<?php $cursor = new mysqli("localhost", "loek", "", "webs"); ?> diff --git a/public/index.php b/public/index.php index 84dc753..cf8e7d1 100644 --- a/public/index.php +++ b/public/index.php @@ -1,5 +1,5 @@ <!DOCTYPE html> -<?php require "db.php"; ?> +<?php require "../lib/db.php"; ?> <html> <head> <?php include 'head.php' ?> diff --git a/public/product.php b/public/product.php index 51ce3db..172a30c 100644 --- a/public/product.php +++ b/public/product.php @@ -1,5 +1,5 @@ <!DOCTYPE html> -<?php require "db.php"; ?> +<?php require "../lib/db.php"; ?> <?php function refuse() { http_response_code(404); @@ -34,6 +34,7 @@ $product = $res->fetch_object(); <span class="price"><?php echo $product->price ?></span> <span class="info"><?php echo $product->description ?></span> <form action="/cart.php" method="post"> + <input type="number" value="<?php echo $product->id ?>" hidden name="product_id"> <input type="submit" value="Toevoegen aan winkelwagen" class="button filled"> </form> </div> diff --git a/public/products.php b/public/products.php index fd3e2a1..433475f 100644 --- a/public/products.php +++ b/public/products.php @@ -1,5 +1,5 @@ <!DOCTYPE html> -<?php require "db.php"; ?> +<?php require "../lib/db.php"; ?> <?php function product_template($product) { $image_path = $product->image ? "/img/product/$product->id-thumb.jpg" : "/img/placeholder.png"; |