accessing an empty querry result

Reply

Join Date: Oct 2008
Posts: 42
Reputation: marcmm is an unknown quantity at this point 
Solved Threads: 0
marcmm marcmm is offline Offline
Light Poster

accessing an empty querry result

 
0
  #1
Dec 20th, 2008
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.

  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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: accessing an empty querry result

 
0
  #2
Dec 20th, 2008
You want to check user name exists or not i.e. avoid duplicate entry in database
  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 20
Reputation: manish.s is an unknown quantity at this point 
Solved Threads: 1
manish.s manish.s is offline Offline
Newbie Poster

Re: accessing an empty querry result

 
0
  #3
Dec 21st, 2008
Aamit,

If condition will be "if($num>0)"
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: accessing an empty querry result

 
0
  #4
Dec 22nd, 2008
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC