54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
// On démarre la session
|
|
session_start();
|
|
// On ajoute la DB
|
|
require_once('../functions/databaseConnection.php');
|
|
|
|
// Si l'utilisateur n'est pas admin il ne peut pas executer le reste du script
|
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
|
header('Location: ../pages/home.php');
|
|
exit;
|
|
}
|
|
|
|
// Si le formulaire à un champ vide
|
|
if (
|
|
!isset($_POST['id']) || !is_numeric($_POST['id']) ||
|
|
empty($_POST['title']) ||
|
|
empty($_POST['xptype']) ||
|
|
empty($_POST['description']) ||
|
|
empty($_POST['duration']) ||
|
|
empty($_POST['imageurl'])
|
|
) { // On renvoie sur admin.php
|
|
header('Location: ../pages/admin.php');
|
|
exit;
|
|
}
|
|
|
|
//On récupère les données pour les mettres en variables locales
|
|
$id = (int) $_POST['id'];
|
|
$title = trim($_POST['title']);
|
|
$xptype = trim($_POST['xptype']);
|
|
$tags = trim($_POST['tags'] ?? '');
|
|
$description = trim($_POST['description']);
|
|
$duration = trim($_POST['duration']);
|
|
$imageurl = trim($_POST['imageurl']);
|
|
|
|
try { // On essaie d'executer une requête qui est préparée
|
|
$stmt = $dbh->prepare('
|
|
UPDATE experiences
|
|
SET title = :title, xptype = :xptype, tags = :tags, description = :description, duration = :duration, image_url = :image_url
|
|
WHERE id = :id
|
|
');
|
|
$stmt->bindValue(':title', $title, PDO::PARAM_STR);
|
|
$stmt->bindValue(':xptype', $xptype, PDO::PARAM_STR);
|
|
$stmt->bindValue(':tags', $tags, PDO::PARAM_STR);
|
|
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
|
|
$stmt->bindValue(':duration', $duration, PDO::PARAM_STR);
|
|
$stmt->bindValue(':image_url', $imageurl, PDO::PARAM_STR);
|
|
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
|
|
$stmt->execute(); // Sinon on renvoie l'erreur
|
|
} catch (PDOException $e) {
|
|
die("Erreur lors de la modification de l experience :" . $e->getMessage());
|
|
}
|
|
// On renvoie l'utilisateur sur admin.php
|
|
header('Location: ../pages/admin.php');
|
|
exit; |