I looked into past answers and was led to believe PHP variables assigned in a header file are global. I must be doing something wrong then. Here's a much-simplified version of my code:
This is my myGlobals.php file:
<?php
$NAMELABEL = "Name";
?>
This is file index.php that 'requires' myGlobals.php then calls a function in a 3rd php file
<?php
require_once 'myGlobals.php';
require_once 'DisplayRecords.php';
displayRecords();
?>
And here is DisplayRecords.php
<?php
function displayRecords()
{
echo '<table border="1">';
echo '<tr>';
echo '<th>' . $NAMELABEL . '</th>';
echo '</tr>';
echo "</table>";
}
?>
This is HIGHLY simplified, only the code causing the error.
The error msg. I get when I run it is:
Notice: Undefined variable: NAMELABEL in C:\xampp\htdocs\fbreverse\DisplayRecords.php on line 29
Now, before I changed to the global variable $NAMELABEL -- I used this and it worked fine:
echo '<th>Name</th>';
by 'fine' I mean that the table was created and it had a header called Name as on of the columns.
NOTE: using single quotes around the html tags above is allowed, and needed if you use a double-quoted string
in the tag, as I did in echo '<table border="1">' -- so I just stayed consisted and stuck with the single quote.
Changing the above example to
echo "<th>" . $NAMELABEL . "</th>";
made zero difference, same error message, Notice: Undefined variable: NAMELABEL in C:\xampp\ht........blah blah
Why isn't $NAMELABEL visible in the function displayRecords() inside DisplayRecords.php?
extract(or not). While the globals bickering is redundant as usual, it's very obviously the least suitable approach for output variables. (Your example is too terse, not sure about constants.)