0

I have a PHP variable that I am trying to be able to update by means of a $_GET request, but the first time the page is loaded, it isn't updated. After the initial page load, if I reload the page again, it is updated. Why won't it work the first time?

PAGE.PHP:

$name = 'Bob';

include('start.php');

echo $name;

START.PHP:

if isset($_GET['name']) {
  $name = $_GET['name'];
}

Example: page.php?name=Mary

5
  • does it shows any errors? Commented Jun 9, 2015 at 20:35
  • provide us more information. What is the current output ? Commented Jun 9, 2015 at 20:37
  • @holpducki No. It's just the first time the page is visited, it will display "Bob". If I refresh the page, it will then show "Mary", but only after a refresh. Commented Jun 9, 2015 at 20:37
  • At least through 5.6.9, START.PHP won't compile. I strongly suspect caching is at play, since the PHP in start isn't running. Commented Jun 9, 2015 at 20:38
  • 2
    If you are to continue developing in PHP please turn on error reporting to make troubleshooting easier. Add this to the top of you scripts: error_reporting(E_ALL); ini_set('display_errors', 1); Commented Jun 9, 2015 at 20:41

1 Answer 1

3

Your start file has a syntax error, therefore the code never gets executed.

if (isset($_GET['name'])) {
   ^--------------------^--- missing

e.g.:

php > if isset($foo) { echo 'foo'; }
PHP Parse error:  syntax error, unexpected 'isset' (T_ISSET), expecting '(' in php shell code on line 1
php > if (isset($foo)) { echo 'foo'; }
php >
Sign up to request clarification or add additional context in comments.

1 Comment

But why it gets executed the second time OP reloads the page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.