Advertisement
Guest User

Login

a guest
Jun 13th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2.    error_reporting(E_ALL);
  3.    ini_set('display_errors',1);
  4.    include("db.php");
  5.    session_start();
  6.    
  7.    $error = '';
  8.    
  9.    if($_SERVER["REQUEST_METHOD"] == "POST") {
  10.       // username and password sent from web form
  11.      
  12.       $myusername = mysqli_real_escape_string($db,$_POST['username']);
  13.       $mypassword = mysqli_real_escape_string($db,$_POST['password']);
  14.      
  15.       $sql = "SELECT customer_id FROM admin WHERE username = '$myusername' and password = '$mypassword'";
  16.       $result = mysqli_query($db,$sql);
  17.       $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  18.       //$active = $row['active']; uncomment this line if database has a column for active
  19.      
  20.       $count = mysqli_num_rows($result);
  21.      
  22.       // If result matched $myusername and $mypassword, table row must be 1 row
  23.        
  24.       if($count == 1) {
  25.          $_SESSION['myusername'] = $myusername;
  26.          $_SESSION['login_user'] = $myusername;
  27.          
  28.          header("location: Welcome.php");
  29.       }else {
  30.          $error = "Your Login Name or Password is invalid";
  31.       }
  32.    }
  33. ?>
  34. <html>
  35.    
  36.    <head>
  37.       <title>Login Page</title>
  38.      
  39.       <style type = "text/css">
  40.          body {
  41.             font-family:Arial, Helvetica, sans-serif;
  42.             font-size:14px;
  43.          }
  44.          
  45.          label {
  46.             font-weight:bold;
  47.             width:100px;
  48.             font-size:14px;
  49.          }
  50.          
  51.          .box {
  52.             border:#666666 solid 1px;
  53.          }
  54.       </style>
  55.      
  56.    </head>
  57.    
  58.    <body bgcolor = "#FFFFFF">
  59.    
  60.       <div align = "center">
  61.          <div style = "width:300px; border: solid 1px #333333; " align = "left">
  62.             <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
  63.                
  64.             <div style = "margin:30px">
  65.                
  66.                <form action = "" method = "post">
  67.                   <label>UserName  :</label><input type = "text" name = "username" class = "box"/><br /><br />
  68.                   <label>Password  :</label><input type = "password" name = "password" class = "box" /><br/><br />
  69.                   <input type = "submit" value = " Submit "/><br />
  70.                </form>
  71.                
  72.                <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
  73.                    
  74.             </div>
  75.                
  76.          </div>
  77.            
  78.       </div>
  79.  
  80.    </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement