Warning: mysql_numrows()

Reply

Join Date: Dec 2008
Posts: 1
Reputation: samtwilliams is an unknown quantity at this point 
Solved Threads: 0
samtwilliams samtwilliams is offline Offline
Newbie Poster

Warning: mysql_numrows()

 
0
  #1
Dec 8th, 2008
HI All,

I am currently following a tutorial on mysql and php and I am getting this error on displaying results ready for an update in a form.

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/site/update.php on line 11

  1. <?
  2. $id=$_GET['id'];
  3. $username="web183-sql";
  4. $password="sqlpassword";
  5. $database="web183-sql";
  6. mysql_connect(localhost,$username,$password);
  7.  
  8. $query=" SELECT * FROM contacts WHERE id='$id'";
  9. $result=mysql_query($query);
  10.  
  11. $num=mysql_numrows($result);
  12.  
  13. mysql_close();
  14.  
  15. $i=0;
  16. while ($i < $num) {
  17.  
  18. $first=mysql_result($result,$i,"first");
  19. $last=mysql_result($result,$i,"last");
  20. $phone=mysql_result($result,$i,"phone");
  21. $mobile=mysql_result($result,$i,"mobile");
  22. $fax=mysql_result($result,$i,"fax");
  23. $email=mysql_result($result,$i,"email");
  24. $web=mysql_result($result,$i,"web");
  25. ?>
  26.  
  27. <form action="updated.php" method="post">
  28. <input type="hidden" name="ud_id" value="<? echo $id; ?>">
  29. First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
  30. Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
  31. Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
  32. Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
  33. Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>
  34. E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
  35. Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>
  36. <input type="Submit" value="Update">
  37. </form>
  38.  
  39. <?
  40. ++$i;
  41. }
  42. ?>

Any ideas.

Thanks
Sam
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: Warning: mysql_numrows()

 
0
  #2
Dec 8th, 2008
Maybe try this... Its What I've used.
$num = mysql_num_rows($result);
it might help.
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Warning: mysql_numrows()

 
0
  #3
Dec 8th, 2008
this most likely means your query failed.

change:
  1. $query=" SELECT * FROM contacts WHERE id='$id'";
  2. $result=mysql_query($query);

to

  1. $query="SELECT * FROM contacts WHERE id='$id'";
  2. $result=mysql_query($query) or die( 'Error: ' . mysql_error() );

you had an extra space in the query which might make it fail, but I am not sure.
Last edited by kkeith29; Dec 8th, 2008 at 7:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,076
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Warning: mysql_numrows()

 
0
  #4
Dec 9th, 2008
Originally Posted by PomonaGrange View Post
Maybe try this... Its What I've used.
$num = mysql_num_rows($result);
it might help.
i think the above is the solution....
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Warning: mysql_numrows()

 
0
  #5
Dec 10th, 2008
Use this..
  1. $num = mysql_num_rows($result);
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 159
Reputation: sarithak is an unknown quantity at this point 
Solved Threads: 6
sarithak sarithak is offline Offline
Junior Poster

Re: Warning: mysql_numrows()

 
0
  #6
Dec 10th, 2008
hi,
the above all solutions looks right...

still u didnt get this try to do this...

echo $id;

i think id value is null....
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Warning: mysql_numrows()

 
0
  #7
Dec 11th, 2008
2 things...

First in your sql query...
There is a space in your sql query..
" Select ......"
change it to :
$sql = "Select ....... ";

Secondly... u are using mysql_result just above the form thing,,

But before using the mysql_result thing, you have already closed the mysql connection.. i.e. mysql_close();

Remove it and move it to last of the page, after the <form>

  1. <?
  2. $id=$_GET['id'];
  3. $username="web183-sql";
  4. $password="sqlpassword";
  5. $database="web183-sql";
  6. mysql_connect(localhost,$username,$password);
  7.  
  8. $query=" SELECT * FROM contacts WHERE id='$id'";
  9. $result=mysql_query($query);
  10.  
  11. $num=mysql_numrows($result);
  12.  
  13. mysql_close();
  14.  
  15. $i=0;
  16. while ($i < $num) {
  17.  
  18. $first=mysql_result($result,$i,"first");
  19. $last=mysql_result($result,$i,"last");
  20. $phone=mysql_result($result,$i,"phone");
  21. $mobile=mysql_result($result,$i,"mobile");
  22. $fax=mysql_result($result,$i,"fax");
  23. $email=mysql_result($result,$i,"email");
  24. $web=mysql_result($result,$i,"web");
  25. ?>
  26.  
  27. <form action="updated.php" method="post">
  28. <input type="hidden" name="ud_id" value="<? echo $id; ?>">
  29. First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
  30. Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
  31. Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
  32. Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
  33. Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>
  34. E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
  35. Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>
  36. <input type="Submit" value="Update">
  37. </form>
  38.  
  39. <?
  40. ++$i;
  41. }
  42. ?><?
  43. $id=$_GET['id'];
  44. $username="web183-sql";
  45. $password="sqlpassword";
  46. $database="web183-sql";
  47. mysql_connect(localhost,$username,$password);
  48.  
  49. $query=" SELECT * FROM contacts WHERE id='$id'";
  50. $result=mysql_query($query);
  51.  
  52. $num=mysql_numrows($result);
  53.  
  54.  
  55. $i=0;
  56. while ($i < $num) {
  57.  
  58. $first=mysql_result($result,$i,"first");
  59. $last=mysql_result($result,$i,"last");
  60. $phone=mysql_result($result,$i,"phone");
  61. $mobile=mysql_result($result,$i,"mobile");
  62. $fax=mysql_result($result,$i,"fax");
  63. $email=mysql_result($result,$i,"email");
  64. $web=mysql_result($result,$i,"web");
  65. ?>
  66.  
  67. <form action="updated.php" method="post">
  68. <input type="hidden" name="ud_id" value="<? echo $id; ?>">
  69. First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
  70. Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
  71. Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
  72. Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
  73. Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>
  74. E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
  75. Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>
  76. <input type="Submit" value="Update">
  77. </form>
  78.  
  79. <?
  80. ++$i;
  81. }
  82.  
  83. mysql_close();
  84. ?>
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC