I already did inner join before this code but then it seems like every time i have multiple queries it doesnt work. But then when I did it single query it seems fine and working
Although it's possible to run multiple queries in one call with PDO, there is not a single reason to do so. Neither your case is an exception. It will never work as you think. Instead of stuffing several queries in one call like this, you need a single query with JOIN.
Another issue with your code is a cargo cult prepared statement. It looks like a real one but protects nothing. You should use parameters in your prepared query.
$sql = "SELECT * FROM hr_details hd, personal_info pi WHERE
hd.personal_info_id=pi.personal_info_id AND hd.personal_info_id=?";
$statement = $connection->prepare($sql);
$statement->execute([$_POST["personal_info_id"]]);
$result = $statement->fetchAll();