Advertisement
Guest User

Voorbeeld

a guest
Feb 26th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <form action="index.php" method="post">
  5. Name: <input type="text" name="name"><br>
  6. E-mail: <input type="text" name="email"><br>
  7. <input type="submit">
  8. </form>
  9.  
  10. </body>
  11. </html>
  12.  
  13. <?php
  14. /*** mysql hostname ***/
  15. $hostname = 'localhost';
  16.  
  17. /*** mysql username ***/
  18. $username = 'username';
  19.  
  20. /*** mysql password ***/
  21. $password = 'password';
  22.  
  23. try {
  24.     $dbh = new PDO("mysql:host=$hostname;dbname=animals", $username, $password);
  25.  
  26.     /*** set the error reporting attribute ***/
  27.     $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  28.  
  29.     /*** prepare the SQL statement ***/
  30.     $stmt = $dbh->prepare("INSERT name=:name, email=:email INTO user");
  31.  
  32.     /*** bind the paramaters ***/
  33.     $stmt->bindParam(':name', $_POST["name"], PDO::PARAM_STR);
  34.     $stmt->bindParam(':email', $_POST["email"], PDO::PARAM_STR);
  35.  
  36.     /*** execute the prepared statement ***/
  37.     $stmt->execute();
  38.  
  39.     /*** close the database connection ***/
  40.     $dbh = null;
  41. }
  42. catch(PDOException $e) {
  43.     echo $e->getMessage();
  44. }
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement