Advertisement
Guest User

Login

a guest
Dec 19th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. if( !empty($_POST['username']) && !empty($_POST['password'])) {
  4.     $username=$_POST['username'];
  5.     $password=$_POST['password'];
  6.  
  7.     $con=mysqli_connect('localhost','root','') or die(mysqli_error());
  8.     mysqli_select_db($con, 'mydb') or die("cannot select DB");
  9.  
  10.     $sql =mysqli_query($con ,"SELECT * FROM users WHERE username='$username' AND password='$password'");
  11.     $result=mysqli_num_rows($sql);
  12.     if($result!=0)
  13.     {
  14.     while($row=mysqli_fetch_assoc($sql))
  15.     {
  16.     $dbusername=$row['username'];
  17.     $dbpassword=$row['password'];
  18.     }
  19.  
  20.     if ($username == $dbusername && $password == $dbpassword)
  21.     {
  22.     session_start();
  23.     $_SESSION['sess_user']=$username;
  24.  
  25.     header("Location: upload.php");
  26.     }
  27.     } else {
  28.     echo "Sorry, invalid username or password!";
  29.     }
  30.  
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement