%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64 User : ndkhermy ( 1200) PHP Version : 8.5.12 Disable Function : NONE Directory : /home1/ndkhermy/public_html/website_6ca89795/ |
Upload File : |
<?php
session_start();
include('dbcon.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_to_wishlist'])) {
$product_id = intval($_POST['product_id']);
$user_id = intval($_POST['user_id']);
if ($user_id <= 0) {
echo "<script>alert('Please log in to add products to the wishlist.'); window.location.href = 'login.php';</script>";
exit;
}
$stmt = $conn->prepare("SELECT * FROM wishlist_items WHERE user_id = ? AND product_id = ?");
$stmt->bind_param("ii", $user_id, $product_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "<script>alert('Product is already in your wishlist.'); window.location.href = 'products.php';</script>";
} else {
$stmt = $conn->prepare("INSERT INTO wishlist_items (user_id, product_id, added_at) VALUES (?, ?, NOW())");
$stmt->bind_param("ii", $user_id, $product_id);
if ($stmt->execute()) {
echo "<script>alert('Product added to wishlist successfully.'); window.location.href = 'products.php';</script>";
} else {
echo "<script>alert('Error adding product to wishlist. Please try again.');</script>";
}
}
$stmt->close();
$conn->close();
} else {
header("Location: products.php");
exit;
}
?>