qr_id route php getDog
This commit is contained in:
69
php/php-dog/getDog.php
Normal file
69
php/php-dog/getDog.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
|
||||
require __DIR__.'/classes/Database.php';
|
||||
//require __DIR__.'/classes/JwtHandler.php';
|
||||
|
||||
function msg($success,$status,$message,$fields,$data = []){
|
||||
return ([
|
||||
'success' => $success,
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'fields' => $message,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
$db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
$returnData = [];
|
||||
$fields = ['fields' => ['qr_id']];
|
||||
|
||||
// IF REQUEST METHOD IS NOT EQUAL TO POST
|
||||
if($_SERVER["REQUEST_METHOD"] != "POST")
|
||||
{
|
||||
$returnData = msg(0,404,'Page Not Found!',$fields,null);
|
||||
}
|
||||
// CHECKING EMPTY FIELDS
|
||||
elseif(!isset($data->qr_id)
|
||||
|| empty(trim($data->qr_id))
|
||||
)
|
||||
{
|
||||
$returnData = msg(0,422,'Please Fill in all Required Fields!',$fields, null);
|
||||
|
||||
}
|
||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||
else
|
||||
{
|
||||
$qr_id = trim($data->qr_id);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
$fetch_user_by_email = "SELECT * FROM `dogs` WHERE `qr_id`=:qr_id";
|
||||
$query_stmt = $conn->prepare($fetch_user_by_email);
|
||||
$query_stmt->bindValue(':qr_id', $email,PDO::PARAM_STR);
|
||||
$query_stmt->execute();
|
||||
|
||||
// IF THE dog IS FOUNDED BY qr_id
|
||||
if($query_stmt->rowCount())
|
||||
{
|
||||
$row = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$returnData = msg(1,200,'get dog',$fields,$row);
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
$returnData = msg(0,500,$e->getMessage(),$fields,null);
|
||||
}
|
||||
|
||||
}
|
||||
echo json_encode($returnData);
|
||||
Reference in New Issue
Block a user