Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = null;
  5. $dbname = "mydb";
  6.  
  7. try {
  8. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9. // set the PDO error mode to exception
  10. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. $sql = "INSERT INTO users (user_username, user_password, user_firstname, user_lastname, user_email)
  12. VALUES ('admin', '" . password_hash("ditiseenwachtwoord", PASSWORD_DEFAULT) . "', 'John', 'Doe', 'john@example.com')";
  13. // use exec() because no results are returned
  14. $conn->exec($sql);
  15. echo "New record created successfully";
  16. }
  17. catch(PDOException $e)
  18. {
  19. echo $sql . "<br>" . $e->getMessage();
  20. }
  21.  
  22. $conn = null;
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement