Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_POST['Username']) && isset($_POST['Password']) && isset($_POST['Database']))
- {
- $username = $_POST['Username'];
- $password = $_POST['Password'];
- $database = $_POST['Database'];
- $totalData = array(
- "message" => "",
- "isSuccess" => 0,
- "sesUsername" => $username,
- "sesPassword" => $password,
- "sesDB" => $database
- );
- try
- {
- $db = new PDO('mysql:host=localhost;dbname=user1', 'root', '');
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $checkUsers = "SELECT
- username, password
- FROM
- users
- WHERE
- username = :username
- AND
- password = :password";
- $userStmt = $db->prepare($checkUsers);
- $userStmt->execute(array(
- ':username' => $username,
- ':password' => $password
- ));
- $user = $userStmt->fetchAll();
- $num_rows = count($user);
- if ($num_rows == 1)
- {
- $totalData["success"] = 1;
- $totalData["message"] = "Logged in successfully.";
- echo json_encode($totalData);
- }
- elseif ($num_rows == 0)
- {
- $totalData["success"] = 0;
- $totalData["message"] = "Could not find user. Please check your username and/or password.";
- echo json_encode($totalData);
- }
- else
- {
- $totalData["success"] = 3;
- $totalData["message"] = "No data found. fix your shit.";
- echo json_encode($totalData);
- }
- }
- catch(PDOException $e)
- {
- $message = $e->getMessage();
- }
- $db = NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement