39 lines
945 B
PHP
39 lines
945 B
PHP
<?php
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
include('include/headscript.php');
|
|
|
|
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
|
|
|
if (!isset($iduserlogin)) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
function setFlash(string $type, string $text): void
|
|
{
|
|
$_SESSION['flash'] = ['type' => $type, 'text' => $text];
|
|
}
|
|
|
|
$shopId = (int)($_POST['shop_id'] ?? 0);
|
|
|
|
if ($shopId <= 0) {
|
|
setFlash('danger', 'Salone non valido.');
|
|
header("Location: my_favourites.php");
|
|
exit;
|
|
}
|
|
|
|
// Rimuove solo il preferito di QUESTO utente (sicurezza: user_id vincolato)
|
|
$stmt = $pdo->prepare("DELETE FROM user_favorite_shops WHERE user_id = ? AND shop_id = ?");
|
|
$stmt->execute([$iduserlogin, $shopId]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
setFlash('success', 'Salone rimosso dai preferiti.');
|
|
} else {
|
|
setFlash('info', 'Il salone non era tra i tuoi preferiti.');
|
|
}
|
|
|
|
header("Location: my_favourites.php");
|
|
exit;
|