Forum Moderators: coopster
I'm trying to use a simple if statement to show an error on the page, my code:
if ( $_REQUEST['error'] == 'nick_exists' ) {
echo "The selected nickname already exists, please select a new Nick Name";
}
which works fine, the problem is that,
if there is no error returned in the querystring, then apache/php gives me this error:
Notice: Undefined variable: error in signupform.php on line 98
line 98 is:
if ( $_REQUEST['error'] == 'nick_exists' ) {
how do i solve this issue?
thanks in advance for your time!
-Ken
error_reporting(0);
This should get rid of the notice, however remember, that you won't see any error at all. Therefore for development reason you should leave error_reporting(E_ALL); and for the ready to use product error_reporting(0);
Or you can correct the statement:
if(isset($_REQUEST['error'])) { if ( $_REQUEST['error'] == 'nick_exists' ) {
echo "The selected nickname already exists, please select a new Nick Name";
}}
if ( isset($_REQUEST['error']) && $_REQUEST['error'] == 'nick_exists' ) {
echo "The selected nickname already exists, please select a new Nick Name";
}
In the above example, PHP first checks to see if the var is set. If it is not, then the second condition will not even be evaluated. The "&&" basically means "and". It's called a logical operator [php.net].
Added: Or you could do it mcibor's way (with two ifs) :)