note 24906 added to control-structures.switch
| From: | neil at neil dot com | Date: | Wed, 04 Sep 2002 15:23:14 +0000 |
| Subject: | note 24906 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-36112@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; ?>
--
http://www.php.net/manual/en/control-structures.switch.php
http://master.php.net/manage/user-notes.php?action=edit+24906
http://master.php.net/manage/user-notes.php?action=delete+24906
http://master.php.net/manage/user-notes.php?action=reject+24906