diff options
Diffstat (limited to 'public/cart.php')
-rw-r--r-- | public/cart.php | 56 |
1 files changed, 47 insertions, 9 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' ?> |