Actualiser api.php
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -208,4 +203,5 @@ switch ($action) {
|
||||
http_response_code(400);
|
||||
echo json_encode(["error" => "Aucun fichier reçu."]);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user