note 24906 deleted from control-structures.switch by jmcastagnetto

From: Date: Wed, 04 Sep 2002 23:14:28 +0000
Subject: note 24906 deleted from control-structures.switch by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-36134@lists.php.net to get a copy of this message
This maybe quite a newbie question but if a a variable has no value then or is not specified then you get a parse error, therefore the Default case for a switch is called only when the variable is declared but not another one of the examples. Currently I have made a page for different error messages using the variable $e and an if statement using ISSET, could you check if this is the write way to go about it: <? if (isset($e)) { // check the error code and generate an appropriate error message switch ($e) { case -1: $message = "No such user."; break; case 0: $message = "Invalid username or password."; break; case 2: $message = "Unauthorized access."; break; default: $message = "An unspecified error occurred."; break; } } else { $message = "An unspecified error occurred."; } ?> <center> <? echo $message; ?>

« previous php.notes (#36134) next »