Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2. $host=""; // Host name
  3. $username=""; // Mysql username
  4. $password=""; // Mysql password
  5. $db_name=""; // Database name
  6. $tbl_name=""; // Table name
  7.  
  8. // Connect to server and select databse.
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect to DB");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12.  
  13. // Send the username and password
  14. $user = $_POST['username'];
  15. $pass = $_POST['password'];
  16.  
  17. if($user && $pass)
  18. {
  19.  
  20. $uname = mysql_real_escape_string(stripslashes($uname));
  21. $passwd = mysql_real_escape_string(stripslashes($passwd));
  22. $sql="SELECT * FROM $tbl_name WHERE `username`='$uname' AND `password`='$passwd'";
  23. $query=mysql_query($sql) or die(mysql_error());
  24.  
  25. if(mysql_num_rows($query) == 1)
  26. {
  27. $row = mysql_fetch_assoc($query); // mysql_fetch_assoc gets the value for each field in the row
  28. $_SESSION['id'] = $row['id']; //creates the first session var
  29. $_SESSION['username'] = $row['username']; // second session var
  30.  
  31. echo "<script type='text/javascript'>window.location='home.php'</script>";
  32. }
  33. else
  34. {
  35. // Username and password are wrong
  36. echo "<script type='text/javascript'>alert('Username and password doesn\'t match!'); window.location='index.php'</script>";
  37. }
  38. }
  39. else
  40. {
  41. // User didnt supply a username/password
  42. echo "<script type='text/javascript'>alert('You need to supply both username and password!'); window.location='index.php'</script>";
  43. }
  44. }
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement