Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. if (isset($_POST['Submit']))://if admin wants to edit category
  2.  
  3. $h1 = $_POST['h1'];
  4. $text = $_POST['text'];
  5.  
  6. $servername = "localhost";
  7. $username = "user";
  8. $password = "password";
  9. $dbname = "dbname";
  10.  
  11. try {
  12. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  13. // set the PDO error mode to exception
  14. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15.  
  16. // Prepare statement
  17. $stmt = $conn->prepare('UPDATE sections (h1, text) values (:h1, :text) WHERE id=1');
  18. $stmt->bindParam(':h1', $h1);
  19. $stmt->bindParam(':text', $text);
  20. // execute the query
  21. $stmt->execute();
  22.  
  23. // echo a message to say the UPDATE succeeded
  24. echo $stmt->rowCount() . " records UPDATED successfully";
  25. }
  26. catch(PDOException $e)
  27. {
  28. echo $sql . "<br>" . $e->getMessage();
  29. }
  30.  
  31. $conn = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement