Advertisement
xxnorxx

Problem with login/register

Nov 18th, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.    
  3.     $servername = "mysql-xxnorxx.alwaysdata.net";
  4.     $username = "xxnorxx";
  5.     $password = "*****";
  6.     $dbName = "xxnorxx_testdb";
  7.    
  8.     $user_username = $_POST["usernamePost"];
  9.     $user_password = $_POST["passwordPost"];
  10.    
  11.     //Make Connection
  12.     $conn = new mysqli($servername, $username, $password, $dbName);
  13.     //Check Connection
  14.     if(!$conn)
  15.     {
  16.         die("Connection Faled.". mysqli_connect_error());
  17.     }
  18.     //else echo("Connection Success");
  19.    
  20.     $sql = "SELECT password FROM users WHERE username = '".$user_username."' ";
  21.     $result = mysqli_query($conn, $sql);
  22.    
  23.    
  24.     //Get the result and confirm login
  25.     if (mysqli_num_rows($result) > 0)
  26.     {
  27.         //show data for each row
  28.         while($row = mysqli_fetch_assoc($result))
  29.         {
  30.             if($row['password'] == $user_password)
  31.             {
  32.                 echo "Login success";
  33.             }
  34.             else
  35.             {
  36.                 echo "Password incorrect";
  37.             }
  38.         }
  39.     }
  40.     else
  41.     {
  42.         echo "user not found";
  43.     }
  44.    
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement