daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Apr 20th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <?php
  3. ob_start();
  4. $host="127.0.0.1"; // Host name
  5. $username="root"; // Mysql username
  6. $password=""; // Mysql password
  7. $db_name="student"; // Database name
  8. $tbl_name="student_login"; // Table name
  9.  
  10. // Connect to server and select databse.
  11. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. mysql_select_db("$db_name")or die("cannot select DB");
  13.  
  14. // Define $myusername and $mypassword
  15. $myusername=$_POST['Username'];
  16. $mypassword=$_POST['Password'];
  17.  
  18. // To protect MySQL injection
  19. $myusername = stripslashes($myusername);
  20. $mypassword = stripslashes($mypassword);
  21. $myusername = mysql_real_escape_string($myusername);
  22. $mypassword = mysql_real_escape_string($mypassword);
  23.  
  24. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  25. $result=mysql_query($sql);
  26.  
  27. // Mysql_num_row is counting table row
  28. $count=mysql_num_rows($result);
  29. // If result matched $myusername and $mypassword, table row must be 1 row
  30.  
  31. if($count==1){
  32. // Register $myusername, $mypassword and redirect to file "login_success.php"
  33. $_SESSION['myusername'] = $myusername;
  34. $_SESSION['mypassword'] = $mypassword;
  35. //header("location:login_success.php");
  36. //Print user login;
  37. echo 'Logged in as '.$_SESSION['myusername'].' <a href="logout2.php">logout</a>';
  38. }
  39. else {
  40. echo "Wrong Username or Password";
  41. }
  42.  
  43. ob_end_flush(); ?>
  44.         <html>
  45.          <body>
  46.         <form name="form1" method = "post" action="checklogin2.php">
  47.     <table class="tableborder" align=center bgcolor="#f0f0f2">
  48.         <tr>
  49.       <td style="padding-bottom: 10px;" colspan="2" class="heading1"><b>Login Required</b></td>
  50.     </tr>
  51.         <tr>
  52.           <td height="30">Username:</td>
  53.           <td><input type="text" name="Username" style="width:15em;">
  54.           </td>
  55.         </tr>
  56.         <tr>
  57.           <td height="30">Password:</td>
  58.           <td><input type="password" name="Password" style="width:15em;">
  59.           </td>
  60.         </tr>
  61.         <tr><td height="30" align="right"><input class="submit" name="register" type="button" value="Register" onClick="window.location='register.php'"></td>
  62.         <td><input name="submit" type="submit" value="Log-in" class="submit"></td></tr>
  63.       </table>
  64.         </form>
  65.          </body>
  66.         </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top