Jump to content

function error_handler RETURNS Undefined variable (menu system)


Zemi

Recommended Posts

This simple menu system worked until I added error_handler

 

 

<?php 
// Variables
$a = "a";
$b = "b";
$c = "c";
// Error Handling
function error_handler ($errno, $errstr, $errfile, $errline) {
    $error_text = 'A error has been caught.<br />'
                    . "Date: " . date("F j, Y, g:ia") . "\n"
                    . "Error Text: $errstr\n"
                    . "File: $errfile\n"
                    . "Line: $errline\n";
    exit ("This website is not available at this time $error_text");
}
set_error_handler('error_handler');
// Page Switch
switch ($page) :
  case "page1" : $a = 1; $file = "page1.php";
            break;
  case "page2" : $b = 1; $file = "page2.php";
            break;
  case "page3" : $c = 1; $file = "page3.php";
            break;
  default : $a = 1; $file = "page1.php";
endswitch;
//Page Switch Function
function nav($text, $unf, $num) {
if ($unf == "1") {
echo "<a href=\"page_switch.php?page=page".$num."\">".$text."</a>";
} else {
echo "<a href=\"page_switch.php?page=page".$num."\">".$text."</a>";
}
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Page Switch</title>
<h1>Page Switch</h1>
<table border="0" cellpadding="0" cellspacing="0" width="70%">
<tr><td width="30%">
<? nav("Page 2",$b,"2"); ?><br />
<? nav("Page 3",$c,"3"); ?><br />
</td><td width="70%">
<? include($file); ?>
</td></tr>
</table>
</body>
</html>

 

 

<h2>page1.php</h2>
<p>This is text of default page</p>

 

<h2>page2.php</h2>
<p>page 2 page 2</p>

 

<h2>page3.php</h2>
<p>page has been switched to page 3</p>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.