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 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 lib/db.php (limited to 'lib') 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; -- cgit v1.2.3