943,794 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 489
  • PHP RSS
Dec 20th, 2008
0

accessing an empty querry result

Expand Post »
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.

PHP Syntax (Toggle Plain Text)
  1. $sql_name_Check="SELECT DISTINCT table.name
  2. FROM table
  3. WHERE table.nume = '$name'";
  4.  
  5. $rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());
  6.  
  7. IF ( ISNULL ($rez_name_Check) )
  8. {
  9. code for adding the new entry
  10. }

SO is there any way to check if a querry result is NULL and if so to execute a series of instructions?
Reputation Points: 10
Solved Threads: 0
Light Poster
marcmm is offline Offline
42 posts
since Oct 2008
Dec 20th, 2008
0

Re: accessing an empty querry result

You want to check user name exists or not i.e. avoid duplicate entry in database
PHP Syntax (Toggle Plain Text)
  1. $sql_name_Check="SELECT table.name
  2. FROM table
  3. WHERE table.nume = '$name'";
  4. $rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());
  5.  
  6. $num=mysql_num_rows($rez_name_Check);
  7. if($num>1)
  8. {
  9. echo "User name already exists ";
  10. }
  11. else
  12. {
  13. echo "User name is available";
  14. //Here insert value of form in database
  15.  
  16. }
Last edited by Aamit; Dec 20th, 2008 at 9:37 am.
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Dec 21st, 2008
0

Re: accessing an empty querry result

Aamit,

If condition will be "if($num>0)"
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 22nd, 2008
0

Re: accessing an empty querry result

PHP Syntax (Toggle Plain Text)
  1. $sql_name_Check="SELECT table.name
  2. FROM table
  3. WHERE table.nume = '$name'";
  4. $rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error());
  5.  
  6. $num=mysql_num_rows($rez_name_Check);
  7. if($num>=1)
  8. {
  9. echo "User name already exists ";
  10. }
  11. else
  12. {
  13. echo "User name is available";
  14. //Here insert value of form in database
  15.  
  16. }
Last edited by Aamit; Dec 22nd, 2008 at 1:32 am.
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: mysql escape string
Next Thread in PHP Forum Timeline: PHP sort control





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC