I have a form on one page that sends information to a PHP script for processing. Once processed, this information is updated in the database and the page redirects back to the form page where the updated results are supposed to display. The PHP does exactly what it's supposed to do, but the updated results are not displayed on the redirect. If I refresh the form page, the updated results display correctly so I assumed that the redirect was happening too soon and added a three second javascript delay before the redirect. That didn't work. I did usleep in my PHP between updated the database and the redirect still inconsistent. Following is the PHP that I'm using. Suggestions??

Code:
$query="delete from `messages` where `messageid` = '$record'";
$result=$db->query($query);

/// I've tried adding usleep(3000) here as well

$query="select * from `messages` where `to` = '".$_SESSION['profileid']."'";
$result=$db->query($query);
$_SESSION['messagecount']=$result->num_rows; /// This is the number that should refresh on redirect

echo '
Deleting messages ...
<script>
setTimeout(function() {
window.location="'.$_SESSION['pagefrom'].'?id='.$_SESSION['lastviewed'].'&purge=true";
},3000);
</script>';
Thanks in advance.
sleepydad