Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2.     $con = mysql_connect("localhost","root","wow");
  3.     if (!$con)
  4.     {
  5.         die('Could not connect: ' . mysql_error());
  6.     }
  7.    
  8.     mysql_select_db("inventory", $con) or die (mysql_error ());
  9.  
  10.     if(isset($_GET['action']))
  11.     {
  12.         switch($_GET['action'])
  13.         {
  14.         case 'checklogin':
  15.         // username and password sent from form
  16.         $loginusername=$_POST['account'];
  17.         $loginpassword=$_POST['password'];
  18.  
  19.         // To protect MySQL injection (more detail about MySQL injection)
  20.         $loginusername = stripslashes($loginusername);
  21.         $loginpassword = stripslashes($loginpassword);
  22.         $loginusername = mysql_real_escape_string($loginusername);
  23.         $loginpassword = mysql_real_escape_string($loginpassword);
  24.  
  25.         $sql="SELECT * FROM accounts WHERE account='$loginusername' and password='$loginpassword'";
  26.         $result=mysql_query($sql);
  27.  
  28.         // Mysql_num_row is counting table row
  29.         $count=mysql_num_rows($result);
  30.  
  31.         if($count==1){
  32.         session_register("loginusername");
  33.         session_register("loginpassword");
  34.         header("location:main.php");
  35.         }
  36.         else {
  37.         echo 'Wrong Username and or Password<br><br><br><br><br>Click <a href="login.php">here</a> to go back to the login page.';
  38.         }
  39.  
  40.         break;
  41.         }
  42.     }
  43.     else
  44.     {
  45.         echo "<html>
  46.         <body>
  47.  
  48.         <form action="?action=checklogin" method="post">
  49.         Account:      <input type="text" name="account" /><br><br>
  50.         Password:   <input type="password" name="password" /><br><br>
  51.         <input type="submit" value="Login" />
  52.         </form>
  53.  
  54.         </body>
  55.         </html>";
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement