Advertisement
Guest User

login.php file

a guest
Apr 1st, 2016
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. DEFINE ('DB_USER', 'root'); //mysql username
  4. DEFINE ('DB_PSWD', 'test'); //mysql password
  5. DEFINE ('DB_HOST', 'localhost');  //mysql host
  6. DEFINE ('DB_NAME', 'accounts');  //mysql databse
  7.  
  8. $dbcon = mysqli_connect(DB_HOST,DB_USER,DB_PSWD,DB_NAME);  //connect to db
  9.  
  10. if (mysqli_connect_errno()) { //check if can connect to db
  11.         echo "Failed to connect to MySQL: " . mysqli_connect_error(); //if cant display the error msg
  12.     }
  13.    
  14.     $myUsername = $_POST['user']; //get the typed user details
  15.     $myPassword = $_POST['pass']; //get the typed password details
  16.    
  17.     $myUsername = stripslashes($myUsername); //this is against sql injection
  18.     $myPassword = stripslashes($myPassword); //this is against sql injection
  19.    
  20.     $query = "SELECT * FROM users WHERE username='$myUsername'
  21.     and password='$myPassword'";   //check if the user and password are correct
  22.     $result = mysqli_query($dbcon,$query); //add the query to results
  23.     $count = mysqli_num_rows($result); //check row number count
  24.    
  25.     if($count==1){ //if correct
  26.         echo 'you are now logged in'; //then log in
  27.     }else{
  28.         echo 'did not work'; //else dont log in
  29.     }
  30.    
  31.    
  32.     mysqli_close($dbcon); //close database connection
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement