Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host=""; // Host name
- $username=""; // Mysql username
- $password=""; // Mysql password
- $db_name=""; // Database name
- $tbl_name=""; // Table name
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password")or die("cannot connect to DB");
- mysql_select_db("$db_name")or die("cannot select DB");
- // Send the username and password
- $user = $_POST['username'];
- $pass = $_POST['password'];
- if($user && $pass)
- {
- $uname = mysql_real_escape_string(stripslashes($uname));
- $passwd = mysql_real_escape_string(stripslashes($passwd));
- $sql="SELECT * FROM $tbl_name WHERE `username`='$uname' AND `password`='$passwd'";
- $query=mysql_query($sql) or die(mysql_error());
- if(mysql_num_rows($query) == 1)
- {
- $row = mysql_fetch_assoc($query); // mysql_fetch_assoc gets the value for each field in the row
- $_SESSION['id'] = $row['id']; //creates the first session var
- $_SESSION['username'] = $row['username']; // second session var
- echo "<script type='text/javascript'>window.location='home.php'</script>";
- }
- else
- {
- // Username and password are wrong
- echo "<script type='text/javascript'>alert('Username and password doesn\'t match!'); window.location='index.php'</script>";
- }
- }
- else
- {
- // User didnt supply a username/password
- echo "<script type='text/javascript'>alert('You need to supply both username and password!'); window.location='index.php'</script>";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement