1
0
mirror of synced 2025-12-28 00:23:25 +00:00

fix(public) better structure

This commit is contained in:
Valentin
2024-06-14 10:48:27 +02:00
parent f9d50f5b2b
commit d7cdb94316
45 changed files with 252 additions and 36 deletions

26
public/updateFavorite.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
session_start();
include __DIR__ . '/../config.php';
include __DIR__ . '/../services/db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['stopId'], $_POST['lineId'], $_POST['action'])) {
$userId = $_SESSION['user_id'];
$stopId = $_POST['stopId'];
$lineId = $_POST['lineId'];
$action = $_POST['action'];
try {
if ($action === 'add') {
$stmt = $conn->prepare("INSERT INTO favorites (userId, stopId, lineId) VALUES (?, ?, ?)");
$stmt->execute([$userId, $stopId, $lineId]);
} elseif ($action === 'remove') {
$stmt = $conn->prepare("DELETE FROM favorites WHERE userId = ? AND stopId = ? AND lineId = ?");
$stmt->execute([$userId, $stopId, $lineId]);
}
echo json_encode(['success' => true]);
} catch (PDOException $e) {
echo json_encode(['error' => $e->getMessage()]);
}
exit();
}
?>