27 lines
669 B
PHP
27 lines
669 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$car_id = $_GET['id'] ?? 0;
|
|
$action = $_GET['action'] ?? 'add';
|
|
|
|
if ($car_id) {
|
|
$pdo = db();
|
|
if ($action === 'add') {
|
|
$stmt = $pdo->prepare("INSERT IGNORE INTO favorites (user_id, car_id) VALUES (?, ?)");
|
|
$stmt->execute([$user_id, $car_id]);
|
|
} else {
|
|
$stmt = $pdo->prepare("DELETE FROM favorites WHERE user_id = ? AND car_id = ?");
|
|
$stmt->execute([$user_id, $car_id]);
|
|
}
|
|
}
|
|
|
|
header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'favorites.php'));
|
|
exit;
|