Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. $template = "edit_post";
  4. $pageTitle = "";
  5. $postToEdit = $_GET['ID'];
  6.  
  7. $db = new PDO('mysql:host=localhost;dbname=blog;charset=utf8','root','3wamysql', [
  8.         PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  9.         PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  10. ]);
  11.  
  12. if (empty($_POST)){
  13.  
  14.     $query = $db->prepare("SELECT ID,title,content FROM `posts` WHERE ID = ?");
  15.  
  16.     // Exécution de la requête
  17.     $query->execute([
  18.  
  19.         //On oublie pas la variable
  20.         $postToEdit
  21.  
  22.     ]);
  23.  
  24.     $oldPost = $query->fetch();
  25.  
  26.     $query = $db ->prepare("SELECT ID,title FROM categories");
  27.  
  28.     $query->execute([
  29.  
  30.     ]);
  31.  
  32.     $categories=$query->fetchAll();
  33.  
  34.  
  35.  
  36.  
  37. } else {
  38.  
  39.     $postInfo = $_POST;
  40.  
  41.     $query = $db->prepare("UPDATE `posts`
  42.         SET title = ?,
  43.             content = ?,
  44.             category_ID = ?,
  45.             updateDate = NOW()
  46.             WHERE ID = ?");
  47.  
  48.     // Exécution de la requête
  49.     $query->execute([
  50.  
  51.         //On oublie pas la variable
  52.         $postInfo["title"],
  53.         $postInfo["content"],
  54.         $postInfo["category"],
  55.         $postInfo["ID"]
  56.  
  57.     ]);
  58.  
  59.  
  60.     header('Location: admin.php');
  61.     exit();
  62. }
  63.  
  64. include 'layout.phtml';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement