Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); //starts a session
- $con = mysql_connect("localhost","username","password"); //saves the connection details to a variable
- if (!$con) //tests if the conection isnt made
- {
- die('Could not connect: ' . mysql_error()); // kills the connection and prints the error
- }
- mysql_select_db("hostafile", $con); // selects the database using this login details ($con)
- 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.
- echo mysql_error(); //if there is a error this show it
- if( $login=='1') //tests if the check finds one correct match
- {
- $loginname=$_POST["username"]; //saves the login name to a variable
- $_SESSION['login']=$loginname; // creates a session that shows they are logged in
- 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
- }
- else
- echo "sorry we where unable to log you in"; // if no matches where found a message is shown saying so.
- mysql_close($con) // closes the connection to the database
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement