how can detect if the username is already exist??
i don't what is lacking in my code. this is my code:
<?php
include( "db.php" );
$first = strip_tags(mysql_real_escape_string($_POST['first']));
$last = strip_tags(mysql_real_escape_string($_POST['last']));
$username = strip_tags(mysql_real_escape_string($_POST['username']));
$password = strip_tags(mysql_real_escape_string($_POST['password']));
$password2 = strip_tags(mysql_real_escape_string($_POST['password2']));
$passwordmd5 = md5($password);
if( empty($first) || empty($last) ||empty($username) || empty($password) || empty($password2))
{
echo "ALL fields required";
}
else{
$userQ = mysql_query("SELECT * FROM admin WHERE 'username' = '{$username}'");
if ($password !== $password2)
{
echo "do not match";
}
else{
mysql_query("INSERT INTO admin (first, last,username,password) Values ('{$first}','{$last}','{$username}','{$passwordmd5}')");
echo "Your Succesfully Registered!";
header("location: adminlogin.php");
}
}
?>
when i click on the register button I can still register even if the username is already exist. thanks in advance..hope u can help me this simple problem.