Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
225
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. if ( empty( $_POST ) ){
  3. ?>
  4. <form name='registration' action='pdo1.php' method='POST'/>
  5. <input type="text" name="user_name">
  6. <input type="password" name="password">
  7. <input type="text" name="email">
  8. <button type="submit">Submit</button>
  9. </form>
  10. <?php
  11. } else {
  12. // host, myU, myP and myDB are all correct
  13. $db_user = 'myU';
  14. $db_pass = 'myP';
  15. $db = new PDO( 'mysql:host=localhost;dbname=myDB', $db_user, $db_pass );
  16.  
  17. $sql = "INSERT INTO users ( user_name, password, email ) VALUES ( :username, :password, :email )";
  18.  
  19. $query = $db->prepare( $sql );
  20. $result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':email'=>$email ) );
  21.  
  22. if($result) {
  23. echo "Worked!";
  24. }
  25. }
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement