Inserting mySQL into a div?

Interesting you ask that, because we both seem to have come to the same conclusion at the same time! I was just about to make a post on here, because I’ve found a solution to my problem, and you’re right, it uses bind_result before fetch(). Here’s the code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="Styles.css"> </head>
<body>
<?php 
include("dbconfig.php");
$result = $mysqli->prepare("SELECT ID, Title, Body, Author FROM posts WHERE ID = ?");
$result->bind_param("s", $_GET['ID']);
$result->execute();
$result->bind_result($id, $title, $body, $author);

while( $row = $result->fetch() )
{
    echo '<div>';
    echo '<h1>'.$title.'</h1>';
    echo '<p>'.$body.'</p>';         
    echo '</div>';
}
?>

<p><a href="./">Back to the homepage</a></p>
    

</body>
</html>

Thank you guys so much for all your help. You’re all awesome, and I would never have found a solution without you guys leading me in the right direction :smiley:

2 Likes