M4tt M4tt - 7 months ago 8
PHP Question

PHP GET parameter not showing without page refresh

any idea what is wrong here. I generate link list from database. When I click link, it navigates to another page, but echo is missing. However, if I check "View page source", I can found my echo. If I want to see it on page, I need to refresh page manually, so I can see my echo. I don't to refresh page, so any idea what is problem here?

Screenshot

Source codes:

page.php:

<?php
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
foreach ($line as $col_value) {
echo '<li><a href="test.php/?name='.$col_value.'">'.$col_value.'</a></li>';
}
}

// Free resultset
pg_free_result($result);

// Closing connection
pg_close($dbconn);
?>


test.php:

<?php
echo 'TEST ';
echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
?>

Answer

In your test.php page, replace your code with the following code:

  <!DOCTYPE html>
  <html>
    <head></head>
    <body>
    <?php
      echo 'TEST ';
      echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
    ?>
    </body>
  </html>

Let me know if it works now!


Edited: Explanation of why this solution worked

The image shown in the question showed 2 windows. The confusion starts there. The window on the left is the browser at work displaying the html code that was rendered, while the window on the right is the "Source Code"! What that means is that the browser probably didn't understand what TESTHELLO dbName meant and made a blank page, but when adding all the default tags, then the browser was happy to interpret it as text within the pages body.

Comments