Hey,
I have a problem with my script, i had it working as far as recording the users information, now i want it to check if the user already exists, to do this i added the bits in bold, now it checks the username fine if i put a username that exists, if the user does not exist it does nothing, i just get a blank page, what could be wrong?
PHP Code:
<?php
if(isset($_POST['register'])){
$usr = $_POST['usr'];
$pwd = $_POST['pwd'];
$confpwd = $_POST['confpwd'];
$email = $_POST['email'];
$squestion = $_POST['squestion'];
$sanswer = $_POST['sanswer'];
$ipaddress = $HTTP_SERVER_VARS['REMOTE_ADDR'];
if(strlen($usr) <= 16 && strlen($usr) >= 3 && strlen($pwd) >= 6 && $pwd == $confpwd && $email <> "" && $squestion <> "" && $sanswer <> ""){
include 'includes/config.php';
include 'includes/dbcon.php';
mysql_real_escape_string($usr);
mysql_real_escape_string($pwd);
mysql_real_escape_string($email);
mysql_real_escape_string($squestion);
mysql_real_escape_string($sanswer);
$pwd = sha1(sha1($pwd).$pwd);
[b] $query_check = "SELECT usr FROM $tbusers WHERE usr = '$usr'";
$result = mysql_query($query_check) or die(mysql_error());
$rows = mysql_num_rows($result) or die(mysql_error());[/b]
[b]if($row <> "0"){
echo "This user already exists, please select a new username.";
}else{[/b]
if($_POST['newsletter'] <> NULL){
$newsl = "1";
} else {
$newsl = "0";
}
$query = "INSERT INTO $tbusers(usr, pass, email, newsletter, squestion, sanswer, ip) VALUES('$usr', '$pwd', '$email', '$newsl', '$squestion', '$answer', '$ipaddress')";
mysql_query($query) or die(mysql_error());
include 'includes/dbclose.php';
[b]}[/b]
} else {
$error = "You have the following errors:<br />";
if(strlen($usr) <= 2 || strlen($usr) >= 17){
$error = $error . "The username must be 3 - 16 characters long.<br />";
}
if(strlen($pwd) < 6){
$error = $error . "Your password must be at least 6 characters long.<br />";
}
if($pwd <> $confpwd){
$error = $error . "Your passwords do not match.<br />";
}
if($email == ""){
$error = $error . "You must provide an email to activate your account.<br />";
}
if($squestion == ""){
$error = $error . "You must provide a security question.<br />";
}
if($sanswer == ""){
$error = $error . "You must provide an answer to your security question.<br />";
}
echo "$error";
}
} else {
echo "<form name=\"form1\" method=\"post\" action=\"\">
Username: (3 - 16 Chars)<br />
<input type=\"text\" name=\"usr\" id=\"usr\"><br />
Password: (Minimum 6 Chars)<br />
<input type=\"password\" name=\"pwd\" id=\"pwd\">
<br />
Confirm:(Must match password)
<br />
<input type=\"password\" name=\"confpwd\" id=\"confpwd\">
<br />
Email: (Needed to activate your account)<br />
<input type=\"text\" name=\"email\" id=\"email\">
<br />Security Question: (If you loose your password you will be asked this)<br />
<input type=\"text\" name=\"squestion\" id=\"squestion\">
<br />Security Answer:(This will be the answer you have to provide to get your password)<br />
<input type=\"text\" name=\"sanswer\" id=\"sanswer\">
<br />
<input type=\"checkbox\" name=\"newsletter\" id=\"newsletter\" /> News letter
<br />
<input type=\"submit\" name=\"register\" id=\"register\" value=\"Register\">
<br />
</form>";
}
?>
Thanks,
Lee.
Edit: just seen the bold doesnt work inside PHP tags, so the bits i added are in the middle of (theres 3 bits)