Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. try {
  2.  
  3. require_once('db.php');
  4.  
  5. $sql1 = "SELECT username FROM administrators WHERE username = '.$username.' ";
  6. $cmd = $conn->prepare($sql1);
  7. $cmd->execute();
  8. $admin = $cmd->fetchAll();
  9. //if the username is greater than 0 in the database say that username already exists
  10.  
  11. if (empty($admin_id) == true){
  12. //set up the sql command
  13. $sql = "INSERT INTO administrators (username, password) VALUES (:username, :password)";
  14. }else{
  15. $sql ="UPDATE administrators SET username = :username, password = :password WHERE admin_id = :admin_id";
  16. }
  17.  
  18.  
  19.  
  20. //5. hash the password for added security
  21. $hashed_password = hash('sha512', $password);
  22.  
  23. //6. execute the save
  24. $cmd = $conn->prepare($sql);
  25.  
  26. $cmd->bindParam(':username', $username, PDO::PARAM_STR, 50);
  27. $cmd->bindParam(':password', $hashed_password, PDO::PARAM_STR, 128);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement