I need someone to check the below code too see if they can advise what I'm doing wrong.
The code need to check for a duplicate entry for some fields, it also needs to check if the field is blank.. if so stop.
But this doesn't input anything to the database, but If I take out the srtlen statments it does...
mysql_select_db($db_name, $connection);
$username = $_POST[username];
$result = mysql_query("SELECT * FROM user where username = '$username'");
if (mysql_num_rows($result) > 0 )
if (strlen($username) == 0)
{
die ("user name already exists in database, or you may have left it blank please use the back button and try again");
}
$wonid = $_POST[wonid];
$result = mysql_query("SELECT * FROM user where wonid = '$wonid'");
if (mysql_num_rows($result) > 0 )
if (strlen($wonid) == 0)
{
die ("The WONID already exists in the database go purchase you own copy of Half life you haxor or read the instructions and enter one and try again using the back button");
}
$gname = $_POST[gname];
$result = mysql_query("SELECT * FROM user where gname = '$gname'");
if (mysql_num_rows($result) > 0 )
if (strlen($gname) == 0)
{
die ("That name is either in use or you have not entered one");
}
$email = $_POST[email];
$result = mysql_query("SELECT * FROM user where email = '$email'");
if (mysql_num_rows($result) > 0 )
if (strlen($email) == 0)
{
die ("That email address is either in use or you have not botherd to enter one, use the back button");
}
else
{
$password = $_POST[password];
$clan = $_POST[clan];
$query = "INSERT INTO user (username, wonid, password, gname, email, clan) Values ('$username', '$wonid', '$password', '$gname', '$email', '$clan')";
mysql_query($query, $connection) or die (mysql_error());
}
I am new to all this, and i know some of what i want can be done in MYSQL, but i can't do it via the database for a while.. long storey..
Any help will be appriciated ..