PHP Rest Search API through Post Method

 api-search.php:


<?php
header('Content-Type: application/json');
header('Acess-Control-Allow-Origin: *');

$data=json_decode(file_get_contents("php://input"), true);

$search_value=$data['search'];

include "config.php";

$sql="SELECT * FROM students WHERE student_name LIKE '%{$search_value}%'";

$result=mysqli_query($conn, $sql) or die("SQL query failed");

if(mysqli_num_rows($result)>0){
    $output=mysqli_fetch_all($result, MYSQLI_ASSOC);
    echo json_encode($output);

}else{
    echo json_encode(array('message'=>'NO Search FOUND', 'status'=>false));

}

?>

Comments

Popular posts from this blog

Send Data Child to Parent Component - React Js

Hide , Show and Toggle in ReactJs

Importance Of Web Content In SEO.