Hello,
PHP PDO code used in this paging
How to convert mysqli?
<?php
include 'connection.php';
if($_POST){
//Data
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$response = []; //Data Response
//Cek username didalam databse
$userQuery = $conn->prepare("SELECT * FROM user where username = ?");
$userQuery->execute(array($username));
$query = $userQuery->fetch();
if($userQuery->rowCount() == 0){
$response['status'] = false;
$response['message'] = "Username Tidak Terdaftar";
} else {
// Ambil password di db
$passwordDB = $query['password'];
if(strcmp(md5($password),$passwordDB) === 0){
$response['status'] = true;
$response['message'] = "Login Berhasil";
$response['data'] = [
'user_id' => $query['id'],
'username' => $query['username'],
'name' => $query['name'],
'email' => $query['email']
];
} else {
$response['status'] = false;
$response['message'] = "Password anda salah";
}
}
//Jadikan data JSON
$json = json_encode($response, JSON_PRETTY_PRINT);
//Print
echo $json;
}