Guest User

Untitled

a guest
Aug 10th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. How to prevent mysql injection in Php before it is submitted to the database [closed]
  2. $stmt = $db->prepare(
  3. 'UPDATE users ' .
  4. 'SET userEmail=:email, userSalt=:salt, userPass=:pass ' .
  5. 'WHERE userId=:userId LIMIT 1' );
  6. $stmt->bindParam( ':email', $this->_email, PDO::PARAM_STR );
  7. $stmt->bindParam( ':salt', $this->_salt, PDO::PARAM_STR );
  8. $stmt->bindParam( ':pass', $this->_password, PDO::PARAM_STR );
  9. $stmt->bindParam( ':userId', $this->_id, PDO::PARAM_INT );
  10. $stmt->execute();
  11.  
  12. $pdo = new PDO($stuff);
  13.  
  14. $stmt = $pdo->prepare('SELECT * FROM foo WHERE bar = :baz');
  15. $stmt->bindParam(':baz', $baz);
  16. $stmt->execute();
  17.  
  18. <?php
  19.  
  20. function hashPassword($str)
  21. {
  22. return hash("sha512", $str . "salt");
  23. //Change so it fits your database configuration.
  24. }
  25.  
  26. $username = mysql_real_escape_string($_POST['username']);
  27. $password = hashPassword($_POST['password']);
  28.  
  29. ?>
Add Comment
Please, Sign In to add comment