mysql_numrows not working??

Reply

Join Date: Jul 2007
Posts: 253
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

mysql_numrows not working??

 
0
  #1
Apr 26th, 2008
Hey

Im having this problem, im sure theres a simple solution, but i cant seem to see it

The code bellow is part of a regestration form validation. Basicly when i ask the database if anyone else exists with the same username, password or email address - it works

BUT

Only if it returns 1 or more rows!
If no-one else exists with the username ect. it returns my error message (couldnt check rows).

  1. <form method="post" name="details">
  2.  
  3. <b class="form_title">First Name:
  4. </b><input type="text" name="first_name" class="form_box" />
  5. <br />
  6.  
  7. <b class="form_title">Last Name:
  8. </b><input type="text" name="last_name" class="form_box"/>
  9. <br />
  10.  
  11. <b class="form_title">Age:
  12. </b><input type="text" name="age" class="form_box" />
  13. <br />
  14.  
  15. <b class="form_title" >Email:
  16. </b><input type="text" name="email" class="form_box" />
  17. <br />
  18.  
  19. <b class="form_title" >Phone:
  20. </b><input type="text" name="phone" class="form_box" />
  21. <br />
  22.  
  23. <b class="form_title">Address:
  24. </b><textarea name="address" class="form_box"></textarea>
  25. <br />
  26.  
  27. <b class="form_title" >Username:
  28. </b><input type="text" name="username" class="form_box"/>
  29. <br />
  30.  
  31. <b class="form_title" >Password:
  32. </b><input type="password" name="password1" class="password"/>
  33. <br />
  34.  
  35. <b class="form_title" >Repeat:
  36. </b><input type="password" name="password2" class="password" />
  37. <br />
  38.  
  39. <b class="form_title">I accept the terms of using this website
  40. </b> <input type="checkbox" name="terms" class="form_box" />
  41. <br />
  42.  
  43. <input type="submit" value="Regester Me"/>
  44.  
  45. </form>
  46.  
  47.  
  48. <?php
  49. $priv = "LIMITED";
  50. $first_name = $_REQUEST["first_name"];
  51. $last_name = $_REQUEST["last_name"];
  52. $age = $_REQUEST["age"];
  53. $email = $_REQUEST["email"];
  54. $phone = $_REQUEST["phone"];
  55. $address = $_REQUEST["address"];
  56. $username = $_REQUEST["username"];
  57. $pass1 = $_REQUEST["password1"];
  58. $pass2 = $_REQUEST["password2"];
  59. $terms = $_REQUEST["terms"];
  60.  
  61.  
  62.  
  63. if (empty($first_name) || empty($last_name) || empty($age) ||
  64. empty($email) || empty($phone) || empty($address) || empty($username) || empty($pass1) || empty($pass2)) {
  65. $error = "You Must Fill In All The Boxs.";
  66. }
  67.  
  68. elseif ($pass1 != $pass2) {
  69. $error = "Your Passwords Must Match.";
  70. }
  71. elseif ($terms != "on") {
  72. $error = "You Must Accept The Terms";
  73. }
  74.  
  75. else {
  76.  
  77. $check_email = "SELECT email,username,password FROM members WHERE
  78. email = '$email' OR
  79. username = '$username' OR
  80. password = '$pass1'";
  81. $check_email_sql = MYSQL_QUERY($check_email) or die ("Could send email check");
  82. $email_rows = MYSQL_NUMROWS($check_email_sql) or die ("couldnt check rows");
  83.  
  84. }
  85. echo $email_rows;
  86.  
  87.  
  88. ?>
  89. <br />
  90. <u class="error"><?php echo $error ; ?></u>
  91. <div id="space">
  92. </div>
  93. </div>


All help would be greatly appreciated!
Thanks
Last edited by peter_budo; Apr 27th, 2008 at 5:05 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 187
Reputation: phper is an unknown quantity at this point 
Solved Threads: 15
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: mysql_numrows not working??

 
0
  #2
Apr 26th, 2008
It may be producing an error because there are no rows.

You might be better to write the script as:

  1. $email_rows = mysql_num_rows($check_email_sql);
  2.  
  3. if($email_rows>0){
  4. echo $email_rows;
  5. }else if($email_rows==0){
  6. echo 'No Rows Found';
  7. }
If my post is useful please add to my reputation.
Thanks.

Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 253
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: mysql_numrows not working??

 
0
  #3
Apr 26th, 2008
Wow
Worked a treat thankyou!

Can i ask why though?
The scripts seem extreamly similar

Thanks again
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 187
Reputation: phper is an unknown quantity at this point 
Solved Threads: 15
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: mysql_numrows not working??

 
1
  #4
Apr 27th, 2008
I think it's because when the row return's zero then php thinks it's an error so it runs the die() function.

I always write my scripts like the one I showed you and I never have a problem.

Please use "Add to Phper's reputation" if you found my post usefull!

Thanks
If my post is useful please add to my reputation.
Thanks.

Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: mysql_numrows not working??

 
0
  #5
Apr 27th, 2008
why would you want to check for password? not needed!

btw $email_rows = MYSQL_NUMROWS($check_email_sql); should be $email_rows = MYSQL_NUMROWS($check_email)


  1. $email_rows =mysql_affected_rows();
  2. if($email_rows>0){
  3. echo $email_rows;
  4. }else if($email_rows==0){
  5. echo 'No Rows Found';
  6. }

you need to use mysql_real_escape_string($username) on db also

username='".mysql_real_escape_string($username)."'
Last edited by peter_budo; Apr 29th, 2008 at 9:46 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 10
Reputation: yangyang is an unknown quantity at this point 
Solved Threads: 0
yangyang's Avatar
yangyang yangyang is offline Offline
Newbie Poster

Re: mysql_numrows not working??

 
0
  #6
Apr 27th, 2008
I believe it's mysql_num_rows(), in addition, in case you wanna switch to mysqli result object, it's $result -> num_rows;
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: mysql_numrows not working??

 
0
  #7
Apr 27th, 2008
ah yes yang, few typos there.

$email_rows = MYSQL_NUMROWS($check_email_sql); should be $email_rows = MYSQL_NUM_ROWS($check_email_sql)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 253
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

Re: mysql_numrows not working??

 
0
  #8
Apr 27th, 2008
Lol
Thanks all
Il mark them up now, oh and i do need to check against current email address in my database because each member is limited to one account, if you get what i meen.

Anyways thanks again, phper in particular.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC