Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does the HTML code after the PHP block not display?

<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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading