Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. <?php
  2.  
  3. $conn = new mysqli('localhost', 'root', '', 'user');
  4.  
  5. if (mysqli_connect_errno()) {
  6. printf("Connect failed: %sn", mysqli_connect_error());
  7. exit();}
  8.  
  9. $uname = $_POST['uname'];
  10. $psw = $_POST['psw'];
  11. $options = [
  12. 'cost' => 12,];
  13. $hashedpassword= password_hash($psw, PASSWORD_BCRYPT, $options);
  14.  
  15. $result = $mysqli->query("SELECT username FROM registration WHERE username = '$uname'");
  16. $row_count = $result->num_rows; if($row_count == 1) {
  17. echo 'User already exists, try another one.'; }
  18. else {
  19.  
  20. $query = "INSERT INTO user (username, password) VALUES(?, ?)";
  21. $statement = $mysqli->prepare($query);
  22.  
  23. $statement->bind_param('ss', $uname, $hashedpassword);
  24.  
  25. if($statement->execute())
  26. {
  27. print 'Success! Last inserted record : ' .$statement->insert_id .'<br />';
  28. }
  29. else
  30. {
  31. die('Error : ('. $mysqli->errno .') '. $mysqli->error);
  32. }
  33. $statement->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement