Hi Sheephat, I am grateful for all the help that is given. I was conscious of the snippet of script not having the tags but I was trying to keep my query as short as possible. Here is the content of the register.php file with the modifications I have made, and I can get the associate member entered into the database but I can not get it to reject if it does not exist.
<?
session_start();
include("database.php");
/**
Returns true if the username has been taken
by another user, false otherwise.
*/
function usernameTaken($username){
global $conn;
if(!get_magic_quotes_gpc()){
$username = addslashes($username);
}
$q = "select username from users where username = '$username'";
$m = "select username from users where username = '$assmem'";
$result = mysql_query($q,$conn);
return (mysql_numrows($result) > 0);
$mresult = mysql_query($m,$conn);
if(!$mresult || (mysql_numrows($mresult) < 1))
return 1; //Indicates associate member failure
}
/**
Inserts the given (username, password) pair
into the database. Returns true on success,
false otherwise.
/
function addNewUser($username, $password, $assmem){
global $conn;
$q = "INSERT INTO users VALUES ('$username', '$password', '$assmem')";
return mysql_query($q,$conn);
}
/**
Displays the appropriate message to the user
after the registration attempt. It displays a
success or failure status depending on a
session variable set during registration.
*/
function displayStatus(){
$uname = $SESSION['reguname'];
if($SESSION['regresult']){
?>
<h1>Registered!</h1>
<p>Thank you <b><? echo $uname; ?></b>, your information has been added to the database, you may now <a href="main.php" title="Login">log in</a>.</p>
<?
}
else{
?>
<h1>Registration Failed</h1>
<p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>
Please try again at a later time.</p>
<?
}
unset($SESSION['reguname']);
unset($SESSION['registered']);
unset($_SESSION['regresult']);
}
if(isset($_SESSION['registered'])){
/**
This is the page that will be displayed after the
registration has been attempted.
*/
?>
<html>
<title>Registration Page</title>
<body>
<? displayStatus(); ?>
</body>
</html>
<?
return;
}
/**
Determines whether or not to show to sign-up form
based on whether the form has been submitted, if it
has, check the database for consistency and create
the new account.
/
if(isset($POST['subjoin'])){
/ Make sure all fields were entered */
if(!$POST['user'] || !$_POST['pass']){
die('You didn\'t fill in a required field.');
}
/ Spruce up username, check length /
$POST['user'] = trim($POST['user']);
if(strlen($_POST['user']) > 30){
die("Sorry, the username is longer than 30 characters, please shorten it.");
}
/ Check if username is already in use /
if(usernameTaken($POST['user'])){
$use = $POST['user'];
die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
}
/* Checks that associate member is in database */
$mresult = confirmAssMem($_POST['assmem']);
/ Checks Associate Member for error /
if($mresult == 1){
die("<CENTER><TABLE ALIGN=\"CENTER\" BORDER=\"10\" CELLSPACING=\"5\" CELLPADDING=\"5\">
<TD><CENTER>Your Associate Member does not exist in our database, please <A HREF=\"Register.php\" TITLE=\"check the accuracy.\">check the accuracy.</A>.");
}
/ Add the new account to the database /
$md5pass = md5($POST['pass']);
$SESSION['reguname'] = $POST['user'];
$SESSION['regassmem'] = $POST['assmem'];
$SESSION['regresult'] = addNewUser($POST['user'], $md5pass, $POST['assmem']);
$_SESSION['registered'] = true;
echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
return;
}
else{
/**
This is the page with the sign-up form, the names
of the input fields are important and should not
be changed.
/
?>
<html>
<title>Registration Page</title>
<body>
<h1>Register</h1>
<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td>Associate Member:</td><td><input type="text" name="assmem" maxlength="30"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
</table>
</form>
</body>
</html>
<?
}
?>