<div class="texts">
<div class="text">
<p>Test paragraph</p>
</div>
<?php
require_once 'twitterdblogin.php';
$connection = new mysqli($hn, $un, $pw, $db);
if ($connection->connect_error) die ("Fatal error.");
$query = 'SELECT * FROM `TWEETS`';
$result = $connection->query($query);
if (!$result) die("Fatal error");
$rows = $result->num_rows;
for ($j = 0; $j < $rows; $j++) {
$result->data_seek($j);
echo '<div class="text">'.htmlspecialchars($result->fetch_assoc()['text']).'<div>';
}
$result->close();
$connection->close();
?>
<div class="text">
<p>Test paragraph</p>
</div><div class="text">
<p>Test paragraph</p>
</div>
</div>
The first "text" div container displays and so does the PHP block successfully, but every HTML code after the PHP block does not display. I have tried entering including an exit(0) function at the end of the script — but to no success.
>Solution :
That because you made a mistake in the line:
$result = $connnection->query($query);
Replace it with the next one:
$result = $connection->query($query);
The second one. Instead of echo
echo '<div class="text">'.htmlspecialchars($result->fetch_assoc()['text']).'<div>';
should be
echo '<div class="text">'.htmlspecialchars($result->fetch_assoc()['text']).'</div>';
You’ve missed a slash.
These mistakes break the code execution and cause that behaviour.