Skip to content

Commit

Permalink
session to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ketertitus committed Mar 25, 2024
1 parent efc70f1 commit fe69c1c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
7 changes: 4 additions & 3 deletions add_product.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
session_start();
include 'dbconfig.php';
include "redisconnect.php";

// Select the last inserted product ID from the product table
$sql = "SELECT MAX(product_id) as last_product_id FROM product";
Expand Down Expand Up @@ -99,9 +100,9 @@
include 'dbconfig.php';

// Example user and merchant values (adjust as needed)
if (isset($_SESSION['merchantid'])) {
$user = $_SESSION['userid'];
$merchant = $_SESSION['merchantid'];
if ($redis->exists('merchantid')) {
$user = $redis->get('userid');
$merchant = $redis->get('merchantid');

// Prepare and bind parameters for the SQL statement
$sql = "INSERT INTO product (name, description, price, quantity, img_url, user_id, merchant_id) VALUES (?, ?, ?, ?, ?, ?, ?)";
Expand Down
4 changes: 3 additions & 1 deletion daily_transactions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
session_start();
include "redisconnect.php";

// Check if the date parameter is set
if (isset($_GET['date'])) {
// Sanitize the date parameter
Expand All @@ -16,7 +18,7 @@
WHERE s.merchant_id = ? AND DATE(s.Timestamp) = ?";

$stmt = $conn->prepare($query);
$stmt->bind_param("is", $_SESSION['merchantid'], $date);
$stmt->bind_param("is", $redis->get('merchantid'), $date);
$stmt->execute();
$result = $stmt->get_result();

Expand Down
7 changes: 5 additions & 2 deletions editInventory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
session_start();

include "redisconnect.php";

if ($_SERVER["REQUEST_METHOD"] == "GET") {
$_SESSION['selectedId'] = $_GET['product_id'];
}
Expand Down Expand Up @@ -150,8 +153,8 @@
$stmt->bind_param("ssdissii", $name, $description, $price, $quantity, $img_url, $user, $merchant, $productId);

// Example user and merchant values (adjust as needed)
$user = $_SESSION['userid'];
$merchant = $_SESSION['merchantid']; // Assuming you store the merchant ID in a session variable
$user = $redis->get('userid');
$merchant = $redis->get('merchantid'); // Assuming you store the merchant ID in a session variable

// Execute the SQL statement to update product details
if ($stmt->execute()) {
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
if ($redis->exists('merchantname')) {
// Display user details if logged in
echo "<h2> " . $redis->get('username') . " </h2>";
// echo "<h2>Welcome, " . $_SESSION['merchantid'] . "</h2>";
// echo "<h2>Welcome, " . $redis->get('merchantid') . "</h2>";
echo "<div class='profile-image'><img src='assets\profile.png' alt='Profile Image'></div>";
} else {
// Display login button if not logged in
Expand Down
10 changes: 8 additions & 2 deletions inventory.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?php
include "redisconnect.php";
// Start session
session_start();

// Close Redis connection (Predis automatically handles connections, so no explicit close is needed)
?>
<!DOCTYPE html>
<html lang="en">

Expand All @@ -15,7 +22,6 @@
<header>
<h1>
<?php
session_start();
if (isset($_SESSION['merchantname'])) {
echo "{$_SESSION['merchantname']} Inventory";
}
Expand Down Expand Up @@ -83,7 +89,7 @@
$stmt = $conn->prepare($sql);

// Bind the parameter to the statement
$stmt->bind_param("i", $_SESSION['merchantid']);
$stmt->bind_param("i", $redis->get('merchantid'));

// Execute the query
$stmt->execute();
Expand Down
10 changes: 8 additions & 2 deletions makeSale.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?php
include "redisconnect.php";
// Start session
session_start();

// Close Redis connection (Predis automatically handles connections, so no explicit close is needed)
?>
<!DOCTYPE html>
<html lang="en">

Expand All @@ -15,7 +22,6 @@
<header>
<h1>
<?php
session_start();
if (isset($_SESSION['merchantname'])) {
echo "{$_SESSION['merchantname']} Sales";
}
Expand Down Expand Up @@ -83,7 +89,7 @@
$stmt = $conn->prepare($sql);

// Bind the parameter to the statement
$stmt->bind_param("i", $_SESSION['merchantid']);
$stmt->bind_param("i", $redis->get('merchantid'));

// Execute the query
$stmt->execute();
Expand Down
12 changes: 9 additions & 3 deletions process_sale.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?php
include "redisconnect.php";
// Start session
session_start();

// Close Redis connection (Predis automatically handles connections, so no explicit close is needed)
?>
<!DOCTYPE html>
<html lang="en">

Expand All @@ -17,7 +24,6 @@
<header>
<h1>
<?php
session_start();
if (isset($_SESSION['merchantname'])) {
echo "{$_SESSION['merchantname']} Invoice";
}
Expand Down Expand Up @@ -76,8 +82,8 @@
$insertStmt->bind_param("iisddii", $productId, $merchantId, $quantity, $price, $discount, $sellingPrice, $userId);

// Get session variables
$userId = $_SESSION['userid'];
$merchantId = $_SESSION['merchantid'];
$userId = $redis->get('userid');
$merchantId = $redis->get('merchantid');

// Initialize arrays to store sale details
$productsSold = [];
Expand Down
5 changes: 4 additions & 1 deletion transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
// Database connection parameters
include 'dbconfig.php';

include "redisconnect.php";


// Query to fetch data grouped by year, month, week, and day
$query = "SELECT YEAR(`Timestamp`) AS year, MONTH(`Timestamp`) AS month, WEEK(`Timestamp`, 1) AS week, DAY(`Timestamp`) AS day, SUM(selling_price) AS total FROM `sale` WHERE merchant_id = ? GROUP BY year, month, week, day";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $_SESSION['merchantid']);
$stmt->bind_param("i", $redis->get('merchantid'));
$stmt->execute();
$result = $stmt->get_result();

Expand Down

0 comments on commit fe69c1c

Please sign in to comment.