SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with $GLOBALS

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

    HTML Code:
    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?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,258
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I don't blame you for being confused. The book is using 2 forms.
    $GLOBALS['loginError']
    $loginError

    If you have the same editition as I do, on page 287 in the "chapter9/admin/login.html.php" code you'll see
    PHP Code:
    <?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?

  3. #3
    SitePoint Member
    Join Date
    May 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well after playing around I tried the code below just to check to see if it was being sent from the access.inc.php page and yes it was being sent. So now I new I had a problem with the htmlout() function.


    PHP Code:
    <?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

    PHP Code:
    include_once $_SERVER['DOCUMENT_ROOT'] .
            
    '/includes/magicquotes.inc.php';


    require_once 
    $_SERVER['DOCUMENT_ROOT'] . '/includes/access.inc.php'
    will not work. I changed it to
    PHP Code:
    include_once('../../includes/magicquotes.inc.php');
    require_once(
    '../../includes/access.inc.php'); 
    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
    PHP Code:
    $_SERVER['DOCUMENT_ROOT'
    on all the pages and all is working well. Hope this helps


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •