Page 1 of 1

login not working

Posted: Sat Nov 12, 2005 8:33 pm
by bruceg
The following code is supposed to print out a list once login is successful. Instead when I hit submit, nothing happens.

here is the code:

Code: Select all

<?
//start a session
session_start() ;
//check if user is coming from a form
if  ($POST[op] =="ds") {
		//check username and password
		if (($_POST[username] != "bruceg_webmaster") || ($_POST[password] !="phoenix")) {
		//handle bad login
		$msg ="<p><font color='red'><strong>Bad Login - Try Again</strong></p>";
		$show_form = "yes";
} else {
		//handle good login
		$_SESSION[valid] = "yes";
		$show_menu ="yes";
		}
} else {
			//determine what to show
			if ($valid == "yes") {
				$show_menu = "yes";
			} else {
				$show_form = "yes";
			}
}
//build form block
$form_block = "<h2>Login</h2>
<form method=POST action=\"$_SERVER[PHP_SELF]\">

$msg
<p><strong>username:</strong><br />
<input type=\"text\" name=\"username\" size=15 maxlength=25></p>
<p><strong>password</strong><br />
<input type=\"password\" name=\"password\" size=15 maxlength=25></p>
<input type=\"hidden\" name=\"op\" value=\"ds\">
<p><input type=\"submit\" name=\"submit\" value=\"login\" /></p>

</form>";
//build menu block
$menu_block = "<h1>My Contact Administration System</h1>
<p><strong>Administration</strong></p>
<ul>
<li><a href=\"show_addcontact.php\">Add a Contact</a></li>
<li><a href=\"pick_moddcontact.php\">Modify a Contact</a></li>
<li><a href=\"pick_delcontact.php\">Delete a Contact</a></li>
</ul>
<p><strong>View Records</strong></p>
<ul>
<li><a href=\"show_contactsbyname.php\">Show Contacts, Ordered by Name</a>
</ul>";
//assign the block to show the $display_block variable
if ($show_form == "yes") {
	$display_block = $form_block;
	} else if ($show_menu == "yes") {
		$display_block = $menu_block;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head>
<meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" />
<title>Inspired Evolution :: Admin Contacts</title>
<?php require('includes/meta_tags.inc'); ?>
<link rel="stylesheet" href="Gilbert.css" type="text/css" media="screen, handheld" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />

</head>
<body>
<!-- begin outer wrapper div --> 

<div id="wrapper_outer">
<a class="skiplink" href="#startcontent">Skip over navigation</a>
<!-- begin header div --> 
<div id="header"><?php require ('rotate.php'); ?><?php showImage () ;?></div><!-- top nav list --> 
<div id="navcontainer">
<ul id="navlist">
<li class="first"><a href="About_Me.php"  title="you know you want to learn more about me">About Me</a></li>
<li><a href="Skillset.php" title="I've got skillz">Skill set</a></li>
<li><a href="Hireme.php" title="hire me dammit!">Hire Me</a></li>
<li><a href="Portfolio.php" title="see my portfolio!">Portfolio</a></li>
<li id="active"><a href="Contact.php" id="current" title="give me a shout">Contact</a></li>
<li><a href="Resume.php"  title="my beautiful resume">R&eacute;sum&eacute;</a></li>
<li><a href="Blog.php"  title="yes, I have one of those too" >Blog</a></li>

</ul>
</div>
<!-- inner content wrapper div --> 
<div id="wrapper_inner">
<!-- breadcrumbs div --> 
<div id="breadcrumbs"><a href="index.php" title="home link" accesskey="1">Home</a>  > >  Contact</div>
<!-- text div --> 
<div id="main_content">
<a name="startcontent" id="startcontent"></a>
<h1 title="Contact Database">Contact Database</h1>
<? echo "$display_block"; ?>
<?php require('includes/bottom_links.inc'); ?></div>

<!-- begin footer --> 
<div id="footer">
<?php require('includes/footer.inc'); ?>
<span class="date"><?
$last_modified = filemtime("index.php");
print("Last Modified ");
print(date("m/j/y h:i", $last_modified));
?></span>
</div>
<p class="footertag">Inspired-Evolution - Web Site: Design, Development, Marketing for Raleigh/Durham, Chapel Hill, Cary North Carolina.</p>

</div>
</div>

</body>

</html>
anyone see what I am missing?

Posted: Sat Nov 12, 2005 11:33 pm
by ambivalent

Code: Select all

if  ($POST[op] =="ds") {
should be

Code: Select all

if  ($_POST[op] =="ds") {
Note the underscore. That error will return false and stop the rest of the block from executing correctly.