Entry
I did exactly from the book. It comes up as " Undefined variable." What's going on here?
I still don't understand *why* I get "undefined variable"; I'm posting two variables from a form; th
Feb 25th, 2008 23:56
dman, Philip Olson, Henrik Hansen, Mac Vee, Jim Vernon, http://www.ttnr.org
Your error level is probably higher than the one the author of the
book used. Still, you should always initialize your variables before
use, for example:
echo $i; // incorrect
$i = 10;
echo $i; // correct
The initialization process is simple, defining a value to the variable
before the use of the variable. A similar problem exists for:
if ($submit) {
echo 'The variable $submit is set';
} else {
echo 'The variable $submit is not set';
}
If $submit is not set, then the else is executed BUT also a PHP error of
level E_NOTICE is generated because $submit is undefined. So, use a
function/construct for this check, such as isset:
if (isset($submit)) {
Good little programmers code with error_reporting all the way up
(E_ALL). The directive is called error_reporting, which is defined in
php.ini One can also use the error_reporting() function to set it
within scripts, as well as .htaccess or ini_set().
http://www.php.net/error_reporting