Problem with $GLOBALS

I recently purchased the book PHP TO MYSQL 5th edition. When I got to the 9th chapter they use

if (!isset($_POST['email']) or $_POST['email'] == '' or
          !isset($_POST['password']) or $_POST['password'] == '')
         $GLOBALS['loginError'] = 'Please fill in both fields';
          return FALSE;

in a function. The only way I can get it too work is if I put an echo in front the $GLOBALS. Is there something missing?

I don’t blame you for being confused. The book is using 2 forms.

If you have the same editition as I do, on page 287 in the “chapter9/admin/login.html.php” code you’ll see

<?php if (isset($loginError)): ?>
<p><?php echo htmlout($loginError); ?></p>
<?php endif; ?>

That’s where it should be echo-ing. If you submit blank inputs do you get the message there?

Well after playing around I tried the code below just to check to see if it was being sent from the page and yes it was being sent. So now I new I had a problem with the htmlout() function.

<?php if (isset($loginError)): ?>
<p><?php var_dump($loginError); ?></p>
<?php endif; ?>

And here is what I found that if you run the pages from the chapter 9 folder inside the main the directory which contains all the chapter folders the code

include_once $_SERVER['DOCUMENT_ROOT'] .

require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/';

will not work. I changed it to


and it worked. For right now since I was running the pages inside the directory for all the code samples I got rid of all the


on all the pages and all is working well. Hope this helps