From 1bb67296c43b662cf00882971fcb3df655d7302b Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 21 May 2023 16:18:05 +0200 Subject: add/remove from cart working --- public/cart.php | 77 ++++++++++++++++++++++++++++++++---------------------- public/product.php | 5 ++-- 2 files changed, 49 insertions(+), 33 deletions(-) (limited to 'public') diff --git a/public/cart.php b/public/cart.php index 34cccbb..d4dfcc6 100644 --- a/public/cart.php +++ b/public/cart.php @@ -2,24 +2,31 @@ -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); -?> + switch($_POST['type']) { + case "delete": { + $statement = $cursor->prepare("delete from orderproduct where product = ? and `order` = cart(?)"); + $statement->bind_param("ii", $_POST['product_id'], $user_id); + $statement->execute(); + break; + } + case "add": { + // ik wou deze functie eigenlijk in een stored procedure doen maar het + // schijnt dat de knappe koppen bij mysql het geen goed idee vonden om + // gewoon 'return' toe te staan binnen de body van een stored + // procedure??? + $statement = $cursor->prepare("select add_to_cart(?, ?)"); + $statement->bind_param("ii", $_POST['product_id'], $user_id); + $statement->execute(); + $statement->get_result()/*->fetch_object()*/; + break; + } + } +} while (false); ?> image ? "/img/product/$item->id-thumb.jpg" : "/img/placeholder.png"; @@ -28,8 +35,8 @@ function item_template($item) { productafbeelding $item->name - - + + $item->price EOF; @@ -45,20 +52,28 @@ EOF;

dingen in de mand van

-
- prepare("select product.id, product.name, product.price, product.image, cart.count from cart join user on user.id = cart.user join product on product.id = cart.product where user.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); ?> -
+ prepare("select product.id, product.name, product.price, product.image, orderproduct.count from orderproduct join product on product.id = orderproduct.product where `order` = cart(?)"); + $statement->bind_param("i", $user_id); + if (!$statement->execute()) break; + $res = $statement->get_result(); + if (!mysqli_num_rows($res)) { + echo "mandje leeg"; + break; + } + echo <<<"EOF" +
+ + EOF; + while ($product = $res->fetch_object()) item_template($product); + echo <<<"EOF" +
+ + EOF; + } while (false); ?>
diff --git a/public/product.php b/public/product.php index 70c511d..18cc936 100644 --- a/public/product.php +++ b/public/product.php @@ -38,8 +38,9 @@ $product = $res->fetch_object(); price ?>

description ?>

- - + + +
-- cgit v1.2.3