Hello. I am trying to create a certain response based upon a $_POST variable and a DATABASE look-up. I am getting the post over to the new script, and I am getting the database objects retrieved correctly, however, I am wanting to give an error message if the user-name exists in the database, and return to the registration script, or, validate that the user-name doesn't exist and then insert into the database, and give a validation response and return to my main script. I have created a script that is called by the registration form, and included in some dummy data and echo statements to observe the response, however, I cannot seem to get the desired results. Here is the script:
<?php
session_start();
include $_SERVER['DOCUMENT_ROOT'] . '/include/config.php';
$username = $_POST['name'];
$password = $_POST['pass'];
$bandname = $_POST['band'];
$banddesc = $_POST['desc'];
$bandgenre = $_POST['genre'];
$useremail = $_POST['email'];
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$password = md5($password);
$query = "SELECT uname FROM users";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $row['uname'] . ' - ' . $username . ' - ';
if($row['uname'] == $username)
{
$_SESSION['regerror'] = 'Sorry, Username already in Database';
$_SESSION['checkit'] = "stop";
break;
} else {
echo 'This name isnt in the database<br>' ;
$_SESSION['checkit'] = "proceed";
$_SESSION['regerror'] = '';
}
echo 'Does it stop here?';
}
if ($_SESSION['checkit'] = "proceed") {
echo 'This is the last bracket';
}
?>
Any ideas on why this doesn't work in the last part of it. Please don't critique on the top segment, as I know that it already works. It is just after the 'RESULT' statement where things don't seem to go correctly.
Thanks;
Ice