When loading my home.php page it should print the data from the select the data from the database 'blog_post' onto the page. However the record gets inserted properly but no data is shown on the page. I have looked up various solutions on here and none of them have seemed to work.
I have looked at many questions on here similar to my problem. None of the answers have seemed to answer my issue. I had tried this using PDO which had worked but with tables, however I do not want to do it that way as it was also a bit much for what I was trying to achieve.
$stmt = $con->prepare("SELECT postTitle, postCont FROM blog_post WHERE
blogid = ? ORDER BY blogid DESC");
$stmt->bind_param('s', $postTitle['postTitle']);
$stmt->execute();
$stmt->bind_result($postTitle, $postCont);
$stmt->fetch();
if(!$postTitle){
echo "<p align='center'>No Blog Currently Available!</p>";
} else {
echo '<div>';
echo '<h1>'.var_dump($postTitle).'</h1>';
echo '<p>'.$postCont.'</p>';
echo '</div>';
}
I expect that when the data is added to the database via my admin.php page. It should then display the data onto home.php.
blogidshold be compared with the bound value of$postTitle?$rowis not an array. As per the docs, fetch() can only return true, false or null. When you work with fetch(), you get the data by using bind_result, not by reading row arrays.$rowisn't an array. Probably a warning is being generated as well (but possibly suppressed). You've bound your output variables to $postTitle and $postCont, so use them.echo '<h1>'.$postTitle.'</h1>'; echo '<p>'.$postCont.'</p>';. I think you've got confused between the syntax you're using now and the syntax you can use when you do it via get_result()