You should not put the $result ($sql) in mysql_errno/mysql_error
mysql_errno ([ resource $link_identifier ] )
Just put nothing.
There can be cases when you need to put
mysql_errno($link);
where $link is your mysql connection.
I would do something like this, for your idea:
$sql=mysql_query( "INSERT INTO......");
$eno = mysql_errno();
if($eno==1062)
{
echo "Somebody was faster." . header("Refresh: 3; URL=pageyoucamefrom.php");
exit();
}
elseif($eno!=0)
{
echo "Error-No. " . $eno . " - " .mysql_error();
}
// else do nothing, errno=0