Entry
How can I get rid of "Warning: undefined variable" after receiving data from a form that doesn't contain data?
Apr 2nd, 2001 22:47
Philip Olson, Paul van Oss,
Either define the variables or do what most people do and turn down
error reporting. See :
Reporting Errors :
-------------------------------------------------------------
http://www.php.net/manual/en/phpdevel-errors.php
Pay special attention to E_NOTICE. For example, the following should
give a similar errors with E_NOTICE on :
print $array[index] // Always use quotes, looks for static variable
// named 'index' first. 'make' in your case.
// sidenote: something like $array[4] is good.
if ($user == '') // Use isset or empty or something similar.
print $notset; // ""
if ($submit) // "" or don't depend on submit buttons.
Messing with empty variables is okay but use quotes around array
index. Always. Except when index is a number (not associative) like
$array[3]. It works without but having php look for static variables
first wastes energy and will cause unexpected results if it happens to
exist. In otherwords, when calling $info[email] PHP will first look
for the static variable named email and then use the index email as
indended.
This setting exists within php.ini, it's the error_reporting setting
and the following function has useful information within it too :
error_reporting -- set which PHP errors are reported :
-------------------------------------------------------------
http://www.php.net/manual/en/function.error-reporting.php