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();
Doesn't that work by doing this?
SELECT * FROM hr_details hd, personal_info pi WHERE hd.personal_info_id=pi.personal_info_id AND personal_info_id = id
You must be careful not to pass the variables directly in the SQL query, by using prepare
http://php.net/manual/en/pdo.prepare.php
$sql = 'SELECT * FROM hr_details hd, personal_info pi WHERE hd.personal_info_id=pi.personal_info_id AND personal_info_id = :id';
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(':id' => $_POST["personal_info_id"]));
$red = $sth->fetchAll();