Guest User

Untitled

a guest
Aug 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.     if ( !$_SESSION['uid'] ) {
  3.         if ( !$_POST['submit'] ) {
  4.         ?>
  5.     <form action="?page=Login} method="post">
  6.         <table>
  7.          <tr>
  8.             <td>Username</td>
  9.             <td><input type="text" name="username"></td>
  10.          </tr>
  11.         <tr>
  12.             <td colspan="2">
  13.              <input type="sumbit" value="Login" name="sumbit">
  14.             </td>
  15.         </tr>
  16.     </table>
  17.     </form>
  18.         <?php
  19.     } else {
  20.         $username = $_POST['username'];
  21.         $password = md5($_POST['password']);
  22.        
  23.         $errors = array();
  24.        
  25.         if ( !$username ) {
  26.             $errors[1] = "The username field is blank.";
  27.         }
  28.        
  29.         if ( !$password ) {
  30.             $errors[2] = "The Password field is blank.";
  31.         }
  32.        
  33.         $sql = "SELECT * FROM `users` WHERE `name`='$username'";
  34.        
  35.         $res = mysql_query($sql) or die(mysql_error());
  36.        
  37.         $exists = mysql_num_rows($res);
  38.        
  39.         if ( count($exists) == 0 ) {
  40.             $errors[3] = "The username does not exist.";
  41.         } else {
  42.        
  43.             $sql = "SELECT * FROM `users` WHERE `name`='$username' AND `password`='$password'";
  44.            
  45.             $res = mysql_query($sql) or die(mysql_error());
  46.            
  47.             $exists = mysql_num_rows($res);
  48.            
  49.             if ( count($exists) == 0 ) {
  50.                 $errors[4] = "the username and password do not match.";
  51.             }
  52.            
  53.         }
  54.        
  55.         if (count($errors) > 0 ) {
  56.             foreach ( $errors as $errors ) {
  57.            
  58.             }
  59.  
  60.        
  61.         }
  62.        
  63.         }
  64.     }
  65.         echo "You are already Logged in!";
  66.        
  67.         include ("pages/Home.php");
  68.     }
  69. ?>
Add Comment
Please, Sign In to add comment