-1

I have try to debug the code saw that after fetching first record error(500 Internal server error) is coming in $row=$conn->fetch_assoc() here is whole code connect file

<?php
$conn = new mysqli("localhost","root","","TMS");
if($conn->connect_error){
    die("connection Failed");
}
?>

and this main file

include('connect.php');
    $data = file_get_contents("php://input");
    $mydata = json_decode($data,true);
    $search = $mydata['search'];

    if(!empty($search))
    {
        $sql = " SELECT * FROM Information 
                WHERE gender = 'Male' and (name LIKE '%$search%'
                OR age LIKE '%$search%' 
                OR height LIKE '%$search%' 
                OR country LIKE '%$search%')";
    }else{
        $sql = "SELECT * FROM Information";
    }

    $result = $conn->query($sql);
    if($result->num_rows>0){
        while($row=$result->fetch_assoc()){
            $data[]=$row;
        }
    }
    echo json_encode($data);
Dharman
  • 26,923
  • 21
  • 73
  • 125
  • 1
    "Internal server error" means "something went wrong, check your logs". Once you find the actual error message, search for it on the attached reference, or across this site. If you really can't find it, post the exact text of the error, and all the code you think is relevant, and someone can help you understand it. – IMSoP May 29 '22 at 08:44
  • _here is whole code_ No it is not. Where is `$conn` defined? – Michel May 29 '22 at 10:02
  • i got the solve of this problem thanks i have didn't declare ```$data = [ ]``` – Harsh Patel May 29 '22 at 13:25

0 Answers0