I wish to know if there is any way to refear to an empty querry result.

I want to implement a safety measure that prevents users from entering duplicate names in a DB. so I colect the value they enter in a textbox, then I create a querry wich checks the DB's name column for values that are identical to the user inputed value.

so basicly if no result is found it should continue to add the entry to the DB.

$sql_name_Check="SELECT DISTINCT table.name
		        FROM table
			WHERE table.nume = '$name'";

	$rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());

	IF ( ISNULL ($rez_name_Check) )
{
code for adding the new entry
}

SO is there any way to check if a querry result is NULL and if so to execute a series of instructions?

You want to check user name exists or not i.e. avoid duplicate entry in database

$sql_name_Check="SELECT  table.name
		        FROM table
			WHERE table.nume = '$name'";
$rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());

$num=mysql_num_rows($rez_name_Check);
if($num>1)
{
echo "User name already exists ";
}
else
{
echo "User name is available";
//Here insert value of form in database

}

Aamit,

If condition will be "if($num>0)"

$sql_name_Check="SELECT  table.name
		        FROM table
			WHERE table.nume = '$name'";
$rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());

$num=mysql_num_rows($rez_name_Check);
if($num>=1)
{
echo "User name already exists ";
}
else
{
echo "User name is available";
//Here insert value of form in database

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.