faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

31 of 51 people (61%) answered Yes
Recently 7 of 10 people (70%) answered Yes

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