Advertisement
Guest User

login.php

a guest
Apr 20th, 2019
176
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.     header('Content-type: application/json');
  3.     include 'db.php';
  4.     $conn = OpenCon();
  5.  
  6.     $username = $_GET['username'];
  7.     $password = $_GET['password'];
  8.  
  9.     $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
  10.     $result = $conn->query($sql);    
  11.  
  12.     //echo "Connected Successfully";
  13.    
  14.     if ($result->num_rows === 1) {
  15.        
  16.         $resultJSON=array('message' => 'success');
  17.  
  18.         while($row = $result->fetch_assoc()) {
  19.            
  20.             array_push($resultJSON['user_id'] = $row['user_id']);
  21.             array_push($resultJSON['user_full_name'] = $row['name']);
  22.             array_push($resultJSON['username'] = $row['username']);
  23.             echo json_encode($resultJSON);
  24.         }
  25.     } else {
  26.         $resultJSON=array('message' => 'error');
  27.         echo json_encode($resultJSON);
  28.     }
  29.  
  30.    
  31.     CloseCon($conn);
  32.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement