Advertisement
Guest User

remysimpson

a guest
Feb 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2. //On vérifie qu'une variable GET à été transmise
  3. if(isset($_GET['id']))
  4. {
  5. $host="localhost";
  6. $dbname="blog";
  7. $name="root";
  8. $mdp="";
  9.  
  10. try
  11. {
  12. // On se connecte à MySQL
  13. $bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $name, $mdp);
  14. }
  15. catch(Exception $e)
  16. {
  17. // En cas d'erreur, on affiche un message et on arrête tout
  18. die('Erreur : '.$e->getMessage());
  19. }
  20. $reponse = $bdd->prepare('SELECT * FROM articles WHERE id ='.$_GET['id']);
  21.  
  22. $inscription = $bdd->prepare('UPDATE `articles` SET `titre` = :titre, `contenu` = :contenu, `auteur` = :auteur, `images` = :images WHERE `articles`.`id` = '.$_GET['id']);
  23. $inscription->bindValue(':titre',$_POST['titre']);
  24. $inscription->bindValue(':contenu',$_POST['contenu'],PDO::PARAM_STR);
  25. $inscription->bindValue(':auteur',$_POST['auteur'],PDO::PARAM_STR);
  26. $inscription->bindValue(':images',$_POST['url'],PDO::PARAM_STR);
  27. }
  28. else die("Aucun utilisateur choisi");
  29. ?>
  30.  
  31. <!DOCTYPE html>
  32. <html lang="fr">
  33.  
  34. <head>
  35. <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  36.  
  37. <meta charset="utf-8">
  38. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  39. <meta name="description" content="">
  40. <meta name="author" content="">
  41.  
  42.  
  43. <!-- Bootstrap core CSS -->
  44. <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  45.  
  46. <!-- Custom styles for this template -->
  47. <link href="css/modern-business.css" rel="stylesheet">
  48.  
  49. </head>
  50.  
  51. <body>
  52.  
  53. <div class="container">
  54.  
  55. <form action="modif.php?id=<?php echo $inscription['id']; ?>" method="post">
  56.  
  57.  
  58. <label for="titre">titre </label>
  59. <input id="perso" type="text" name="titre" value="<?php echo $inscription['titre'];?>"><br>
  60. <label for="titre">Contenu de l'article</label>
  61. <textarea id="perso" type="text" name="contenu"> </textarea><br>
  62. <label for="titre"> Nom de l'auteur</label>
  63. <input id="perso" type="text" name="auteur" value="<?php echo $_SESSION['pseudo']?>" readonly=""><br>
  64. <label for="img"> Image de l'article </label> <br>
  65. <input id="img" type="text" name="url"><br>
  66.  
  67. </p>
  68. <p><input type="submit" value="ok"></p>
  69.  
  70. </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement