Guest User

Untitled

a guest
Mar 22nd, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";$username = "";$password = "";$dbname = "";
  3. $id=$_GET['id'];
  4.  
  5. try {
  6. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  7. // set the PDO error mode to exception
  8. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  9.  
  10. $stmt = $conn->prepare("SELECT title, caption, url, main_image, ordering, state FROM slide WHERE id='$id'");
  11. $stmt->execute();
  12.  
  13. // set the resulting array to associative
  14. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  15. foreach($stmt->fetchAll() as $key=>$val)
  16. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  17. $title = $_POST["title"];
  18. $caption = $_POST["caption"];
  19. $sql = "UPDATE slide SET title='$title', caption='$caption' WHERE id='$id'";
  20. // Prepare statement
  21. $stmt = $conn->prepare($sql);
  22. // execute the query
  23. $stmt->execute();
  24. // echo a message to say the UPDATE succeeded
  25. header("Location: edit.php?id=$id");
  26. }
  27. }
  28. catch(PDOException $e)
  29. {
  30. echo $sql . "<br>" . $e->getMessage();
  31. }
  32. $conn = null;
  33. ?>
  34.  
  35. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  36. <p><label>Title</label><input type="text" name="title" value="<?php echo $val['title']; ?>"></p>
  37. <p><label>caption</label><input type="text" name="caption" value="<?php echo $val['caption']; ?>"></p>
  38. <p><input type="submit" name="submit" value="Submit" onclick="mySuccessFunction()"></p>
  39. </form>
Add Comment
Please, Sign In to add comment