Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. include 'db.php';
  3.  
  4. if (isset($_POST['action']) && $_POST['action'] == 'login') {
  5.     $username=$_POST['username'];
  6.     $password=$_POST['password'];
  7.    
  8.     /*  Important: this "works", but you absolutely need to validate and escape strings before using them in a query.
  9.         Also, the mysql extension is deprecated (old and not used anymore) so you should use mysqli or PDO instead
  10.     */
  11.    
  12.     /* Here I just escape the strings to avoid SQL injection attacks, but it can be done better before finalizing the project */
  13.     $username = mysql_real_escape_string($username);
  14.     $password = mysql_real_escape_string($password);
  15.    
  16.     $query=mysql_query("SELECT users FROM ccmarket WHERE username='$username' AND password='$password'");
  17.     $row=mysql_num_rows($query);
  18.  
  19.  
  20.     if($row<=0)
  21.     {
  22.         echo 0;
  23.     }
  24.     else
  25.     {
  26.         echo 1;
  27.     }
  28.  
  29.  
  30.  
  31. }
  32. else
  33. {
  34.     echo 2;
  35. }
  36.  
  37.  
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement