Image

Imagegwynn_aaron wrote in Imagephp

Trying something a little different

I'm following an example from a book, trying to create a means to login to part of the site I'm working on. The example has me use this code:

<?
if ($_POST["op"] == "ds") {
if (($_POST["username"] != "admin") || ($_POST["password"] != "Verdant1137")) {
$msg = "<p style=\"color: #990000; font-weight: bold;\">Bad Username or Password<br /><span style=\"font-weight: normal;\">Please check and try again.</span></p>";
$show_form = "yes";
} else {
session_register('valid');
$_SESSION["valid"] = "yes";
}
} else {
if ($_SESSION["valid"] == "yes") {
$show_menu = "yes";
} else {
$show_form = "yes";
}
}

$form_block = "
<p class=\"head\">Admin Login</p>
<form method=\"post\" action=\"$PHP_SELF\">
<div class=\"boxed\">
$msg
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td style=\"padding-right: 10px;\" width=\"20%\" align=\"left\" valign=\"top\"><p class=\"smaller\"><strong>USERNAME:</strong><br /><input type=\"text\" name=\"username\" size=\"15\" maxlength=\"25\" /></p></td>
<td width=\"80%\" align=\"left\" valign=\"top\"><p class=\"smaller\"><strong>PASSWORD:</strong><br /><input type=\"password\" name=\"password\" size=\"15\" maxlength=\"25\" /></p></td>
</tr>
</table>
<input type=\"hidden\" name=\"op\" value=\"ds\" />
<p><input class=\"button\" type=\"submit\" name=\"submit\" value=\"Login\" /></p>
</div>
</form>
";

$menu_block = "
<p class=\"head\">Admin Functions</p>
<p>
<form>
<input class=\"button\" type=\"button\" value=\"Add a Product\" onClick=\"goToAdd()\" />
<input class=\"button\" type=\"button\" value=\"Modify a Product\" onClick=\"goToModify()\" />
<input class=\"button\" type=\"button\" value=\"Delete a Product\" onClick=\"goToDelete()\" />
</form>
</p>
";

if ($show_form == "yes") {
$display_block = $form_block;
} else {
$display_block = $menu_block;
}
?>


Now what is supposed to happen is that you type in the correct username and password and then you get a little menu of three buttons. If you don't put the information in correctly then it displays the login form with a message above it saying that you put in bad information. Of course neither of these things is happening. Instead I type in the two pieces of information (right or wrong, doesn't matter), hit submit, and the page reloads but neither gives me an error message nor shows me the menu.

Can some of you fine folks take a look at this code and tell me is you see anything blatantly wrong with it? I've typed the PHP portions of it exactly as they appear in the book, so if there is an error then it is probably in the book (which wouldn't be the first time, I'm afraid). Thank you.