Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $template = "edit_post";
- $pageTitle = "";
- $postToEdit = $_GET['ID'];
- $db = new PDO('mysql:host=localhost;dbname=blog;charset=utf8','root','3wamysql', [
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ]);
- if (empty($_POST)){
- $query = $db->prepare("SELECT ID,title,content FROM `posts` WHERE ID = ?");
- // Exécution de la requête
- $query->execute([
- //On oublie pas la variable
- $postToEdit
- ]);
- $oldPost = $query->fetch();
- $query = $db ->prepare("SELECT ID,title FROM categories");
- $query->execute([
- ]);
- $categories=$query->fetchAll();
- } else {
- $postInfo = $_POST;
- $query = $db->prepare("UPDATE `posts`
- SET title = ?,
- content = ?,
- category_ID = ?,
- updateDate = NOW()
- WHERE ID = ?");
- // Exécution de la requête
- $query->execute([
- //On oublie pas la variable
- $postInfo["title"],
- $postInfo["content"],
- $postInfo["category"],
- $postInfo["ID"]
- ]);
- header('Location: admin.php');
- exit();
- }
- include 'layout.phtml';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement