Advertisement
Voltex

response

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