Actualiser api.php

This commit is contained in:
2026-06-18 16:51:36 +02:00
parent a6249a37c7
commit c3418f0fbc
+2 -6
View File
@@ -17,8 +17,7 @@ try {
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
// NOUVEAU : Création automatique des tables si elles n'existent pas
// Cela évite les erreurs SQL lors de la toute première exécution de l'application
// Création automatique des tables si elles n'existent pas
$pdo->exec("CREATE TABLE IF NOT EXISTS users (
id INT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
@@ -56,7 +55,6 @@ try {
exit;
}
// CORRECTION : Protection contre les valeurs nulles
function makeStableId($title, $year) {
$key = strtolower(trim($title ?? '')) . '|' . trim($year ?? '');
return (abs(crc32($key)) % 2000000000) + 100000000;
@@ -118,9 +116,7 @@ switch ($action) {
case 'save_film':
checkAuth($pdo);
$type = $data['type'] ?? 'critique';
$table = ($type === 'videotheque') ? 'videotheque' : 'critiques';
// CORRECTION : Protection avec `?? ''` sur les champs title et year
$id = !empty($data['id']) ? $data['id'] : makeStableId($data['title'] ?? '', $data['year'] ?? '0000');
if ($type === 'critique') {
@@ -167,7 +163,6 @@ switch ($action) {
case 'bulk_delete':
checkAuth($pdo);
$ids = $data['ids'] ?? [];
// CORRECTION : Protection sur type pour éviter un warning PHP
$type = $data['type'] ?? 'critique';
$table = ($type === 'videotheque') ? 'videotheque' : 'critiques';
@@ -209,3 +204,4 @@ switch ($action) {
echo json_encode(["error" => "Aucun fichier reçu."]);
}
break;
}