Advertisement
Guest User

Untitled

a guest
May 16th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2. session_start(); //starts a session
  3. $con = mysql_connect("localhost","username","password"); //saves the connection details to a variable
  4. if (!$con) //tests if the conection isnt made
  5.   {
  6.   die('Could not connect: ' . mysql_error()); // kills the connection and prints the error
  7.   }
  8.  
  9. mysql_select_db("hostafile", $con); // selects the database using this login details ($con)
  10.  
  11. list($login) = mysql_fetch_row(mysql_query("SELECT COUNT( *) FROM users WHERE username = '".$_POST['username']."' AND password = '".$_POST['password']."'")); //checks through the database for the matchign login detals.
  12. echo mysql_error(); //if there is a error this show it
  13. if( $login=='1') //tests if the check finds one correct match
  14. {
  15. $loginname=$_POST["username"]; //saves the login name to a variable
  16. $_SESSION['login']=$loginname; // creates a session that shows they are logged in
  17. print("<script language = 'javascript'>alert('You have been logged in');window.location='index.php';</script>"); // shows a javascript pop up saying they have been logged in
  18. }
  19. else
  20. echo "sorry we where unable to log you in"; // if no matches where found a message is shown saying so.
  21.  
  22. mysql_close($con) // closes the connection to the database
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement