I tried your solution to my part. It works at first time then if I add different username, it come in error that it already used although that username is not exist in my sql database.
Here is my codes:
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$first=$_POST['first'];
$query = "INSERT INTO contacts VALUES ('','$first','','','','','')";
// assume $sql has your insert query, and you have a unique key defined for the table:
$result = mysql_query($query);
if(!$result)
{
if(mysql_errno() == 1062) // 1062 is "duplicate entry" error
{
echo "Sorry, that username is already taken; please try another.";
}
else
{
// some other mysql error:
die("DB insert failed: " . mysql_error());
}
}
else
{
if(mysql_affected_rows())
{
echo "Record successfully added to DB";
}
else
{
die("Unknown error occurred, record not inserted");
}
}
mysql_query($query);
mysql_close();
?>
what did i miss? Thanks.
Daniel Pinnell