Advertisement
gitlez

YA: Testing Username/Password Against Database

May 23rd, 2012
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2. $connection = mysql_connect('localhost','root','') or die('Couldn\'t Connect to MySQL: ' . mysql_error();
  3. mysql_select_db("DATABASE_NAME", $connection) or die('Couldn\'t Select Database: ' . mysql_error($connection);
  4. // Because the script will die() if there were errors, no need to check if there were.
  5.  
  6. // Later on, look into MySQL Injection Protection
  7. $Log_In_Username = $_POST["Log_In_Username"];
  8. $Log_In_Password = $_POST["Log_In_Password"];
  9.  
  10. $sql = "SELECT Username FROM temp_users WHERE Username='" . $Log_In_Username . "' AND Password='" . $Log_In_Password . "' LIMIT 1"; // I'm assuming you are matching the username and not the email, but I could be wrong. Check for the two conditions, will save you having to compare it later.
  11.  
  12. $result = mysql_query($sql) or die('Couldn\'t complete Query. Error: ' . mysql_error($connection));
  13.  
  14. if (mysql_num_rows($result) > 0){
  15.     echo 'Username/Password Combo Match Input';
  16. }else{
  17.     header ("Location: Username_Not_Found.html");
  18. }
  19.  
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement