title: Using $_SERVER['DOCUMENT_ROOT'] means I can't access variables in an included file
body: <p>I'm calling a database config file (db_config.php) in my header.php file. I'm calling header.php in my template (location.php) I need to access the variables within the db config file as I'm running queries that return a result, which I am then calling in the template.</p>
  
  <p>So in my db_config.php file I have the following:</p>
  
  <pre><code>$area_query = "SELECT * FROM `locations` where `type` = 'area'";
  
  mysqli_query($db, $area_query) or die('Error querying database.');
  
  $area_result = mysqli_query($db, $area_query);
  
  if (!$area_result) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
  }
  </code></pre>
  
  <p>Then in a file called locations.php I am looping through the result of 
      the above using:</p>
  
  <pre><code>            while ($row = mysqli_fetch_array($area_result))
          {
              echo "&lt;li class='location-list-item'&gt;&lt;a href='location/$row[name]'&gt;&lt;span class='initial-letter'&gt;".mb_substr($row['name'],0,1)."&lt;/span&gt;".$row['name']." &lt;i class=\"fa fa-chevron-circle-right\" aria-hidden=\"true\"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;";
          }
  </code></pre>
  
  <p>This works fine if I include the db_config.php in header.php using the following:</p>
  
  <pre><code>include("config/db_config.php");
  </code></pre>
  
  <p>However if I use:</p>
  
  <pre><code>include($_SERVER['DOCUMENT_ROOT']."/config/db_config.php");
  </code></pre>
  
  <p>It finds the db_config.php as expected (as echoing something in db_config.php outputs when visiting locations.php file) but I can't access $area_result. I get the following error:</p>
  
  <pre><code>Notice
  : Undefined variable: area_result
  on line
  28
  
  
  Warning
  : mysqli_fetch_array() expects parameter 1 to be mysqli_result, null 
  given in
  locations.php
  on line
  28
  </code></pre>
  
  <p>I'm confused as to why using $_SERVER['DOCUMENT_ROOT'] prevents me from accessing the variable? I need to use $_SERVER['DOCUMENT_ROOT'] for file path reasons.</p>
  
  <p>To clarify, in locations.php I am including header.php which in turn is including db_config.php. I can echo stuff in db_config that outputs when visiting locations.php but I can't access the variables.</p>
  
  <p>Thank you.</p>