943,589 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1250
  • PHP RSS
Dec 8th, 2008
0

Warning: mysql_numrows()

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

PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
samtwilliams is offline Offline
1 posts
since Dec 2008
Dec 8th, 2008
0

Re: Warning: mysql_numrows()

Maybe try this... Its What I've used.
$num = mysql_num_rows($result);
it might help.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Dec 8th, 2008
0

Re: Warning: mysql_numrows()

this most likely means your query failed.

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

to

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Dec 9th, 2008
0

Re: Warning: mysql_numrows()

Maybe try this... Its What I've used.
$num = mysql_num_rows($result);
it might help.
i think the above is the solution....
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Dec 10th, 2008
0

Re: Warning: mysql_numrows()

Use this..
PHP Syntax (Toggle Plain Text)
  1. $num = mysql_num_rows($result);
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Dec 10th, 2008
0

Re: Warning: mysql_numrows()

hi,
the above all solutions looks right...

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

echo $id;

i think id value is null....
Reputation Points: 10
Solved Threads: 7
Junior Poster
sarithak is offline Offline
183 posts
since Aug 2008
Dec 11th, 2008
0

Re: Warning: mysql_numrows()

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>

php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 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: header problems
Next Thread in PHP Forum Timeline: problem passing a NULL value to MySQL using a php variable





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


Follow us on Twitter


© 2011 DaniWeb® LLC