I'm trying to make a simple login screen with php, but every time I submit the form(with correct values) I am returned to the Login page with the error "Invalid login, try again" shown.

I can't think of any reason why this will not work, the variables are correct as is the database, table and elements.


   // Check for alphanumeric values
	$regExpression = "^[a-zA-Z0-9]+$";
	$uname  = ereg( $regExpression, $_REQUEST['username'])? $_REQUEST['username'] : "";
	$psswd1 = ereg( $regExpression, $_REQUEST['password'])? $_REQUEST['password'] : "";
	// now try to authenticate these values

	// Query database to see if the name and password are valid
	$db_link = db_connect("forumch");
	$query = "SELECT * FROM users WHERE username='$uname' "
            ." AND password = '$psswd1'";
	$result  = mysql_query($query);

      $_SESSION['valid_user'] = $uname;
      $_SESSION['authenticated'] = true;
	  display_members_page();   // function
      display_login_page("Invalid login, try again");
else // first time so display form to login
   display_login_page("Please log in");

I think the problem may be these two lines: between lines 17 and 25
But I've been looking at this for a couple of hours now and I still can't get it.
Here is the remainder of my code:

function display_login_page($message)
<head><title>Members Login Page</title></head>
<h1>Login Page</h1>
<h2><?php echo $message ?></h2>
<form method="POST">
<table border="1">
   <table border="0">
   <tr><td>User Name:</td>
   <td><input type="text" name="userid"></td</tr>
   <td><input type="password" name="password"></td>
   <tr><td colspan=2 align=center>
   <input type="submit" name="submit" value="Log in"></td></tr>

function display_members_page()
<html><head><title>Members Page</title></head>
You have successfully logged in as user
<strong><?php echo $_SESSION['valid-user']?></strong>
<a href="members.php?<?php echo SID?>">Member
<a href="logout.php?<?php echo SID?>">Logout</a>
<?php } ?>


Never mind. The name of the first form field was wrong. Should have been "username".