Advertisement
Guest User

JAVA JSON RETRIEVER ANDROID

a guest
Apr 26th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['Username']) && isset($_POST['Password']) && isset($_POST['Database']))
  4. {
  5.     $username = $_POST['Username'];
  6.     $password = $_POST['Password'];
  7.     $database = $_POST['Database'];
  8.     $totalData = array(
  9.         "message" => "",
  10.         "isSuccess" => 0,
  11.         "sesUsername" => $username,
  12.         "sesPassword" => $password,
  13.         "sesDB" => $database
  14.     );
  15.     try
  16.     {
  17.         $db = new PDO('mysql:host=localhost;dbname=user1', 'root', '');
  18.         $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19.         $checkUsers = "SELECT
  20.                        username, password
  21.                    FROM
  22.                        users
  23.                    WHERE
  24.                        username = :username
  25.                    AND
  26.                        password = :password";
  27.         $userStmt = $db->prepare($checkUsers);
  28.         $userStmt->execute(array(
  29.             ':username' => $username,
  30.             ':password' => $password
  31.         ));
  32.         $user = $userStmt->fetchAll();
  33.         $num_rows = count($user);
  34.         if ($num_rows == 1)
  35.         {
  36.             $totalData["success"] = 1;
  37.             $totalData["message"] = "Logged in successfully.";
  38.             echo json_encode($totalData);
  39.         }
  40.         elseif ($num_rows == 0)
  41.         {
  42.             $totalData["success"] = 0;
  43.             $totalData["message"] = "Could not find user. Please check your username and/or password.";
  44.             echo json_encode($totalData);
  45.         }
  46.         else
  47.         {
  48.             $totalData["success"] = 3;
  49.             $totalData["message"] = "No data found. fix your shit.";
  50.             echo json_encode($totalData);
  51.         }
  52.     }
  53.  
  54.     catch(PDOException $e)
  55.     {
  56.         $message = $e->getMessage();
  57.     }
  58.  
  59.     $db = NULL;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement