From 07d9bcf6b55a7aa866397def09c300347d9c88ea Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 9 May 2023 14:50:10 +0200 Subject: WIP show cart count --- lib/db.php | 1 + lib/login.php | 27 +++++++++++++++++++++++--- public/cart.php | 56 ++++++++++++++++++++++++++++++++++++++++++++--------- public/db.php | 1 - public/index.php | 2 +- public/product.php | 3 ++- public/products.php | 2 +- 7 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 lib/db.php delete mode 100644 public/db.php diff --git a/lib/db.php b/lib/db.php new file mode 100644 index 0000000..6d158b7 --- /dev/null +++ b/lib/db.php @@ -0,0 +1 @@ + diff --git a/lib/login.php b/lib/login.php index 3467994..39dc612 100644 --- a/lib/login.php +++ b/lib/login.php @@ -1,13 +1,34 @@ prepare("select sum(cart.count) as 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()) return 0; + $res = $statement->get_result(); + if (!mysqli_num_rows($res)) return 0; + $obj = $res->fetch_object(); + return $obj->count; +} + $logged_in = check_login(); -$cart_count = 0; +$cart_count = get_cart_count(); function if_logged_in($is, $redirect, $back = false) { global $logged_in; 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 @@ + +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); +?> +image ? "/img/product/$item->id-thumb.jpg" : "/img/placeholder.png"; + echo <<<"EOF" +
+ productafbeelding + $item->name + + + + $item->price +
+EOF; +} +?> @@ -10,16 +44,20 @@
-

dingen in je mand

+

dingen in de mand van

-
- productafbeelding - courgette - - - - 3,45 -
+ 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); ?>
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 @@ - 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 @@ - + 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 @@ - + fetch_object(); price ?> description ?>
+
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 @@ - + image ? "/img/product/$product->id-thumb.jpg" : "/img/placeholder.png"; -- cgit v1.2.3