Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

32 of 53 people (60%) answered Yes
Recently 7 of 10 people (70%) answered Yes


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

Nov 27th, 2008 09:56
mesothelioma asbestos, dman, Philip Olson, Henrik Hansen, Mac Vee, Jim Vernon,

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 
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().