0

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?

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Aamit
0

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

}
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

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.