mysql_numrows(): supplied argument is not a valid MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tobimichigan
Forum Commoner
Posts: 48
Joined: Sun May 10, 2009 1:35 pm

mysql_numrows(): supplied argument is not a valid MySQL

Post by tobimichigan »

Code gurus, Hi again,
Please I need a pointer to correct this specific error:

Code: Select all

 
<?php
$pfno=$_GET["pfno"];
$query=mysql_query("Select * From user_table where pfno='$pfno'") or die (mysql_error());
$result=mysql_query($query);
 
$num=mysql_numrows($result);
echo "<p> PFNO : ".$_SESSION["pfno"]. "<p>Logged in:  " .date("m/d/Y", $_SESSION["valid_time"]);
$i=0;
while ($i < $num) {
 
$pfno = mysql_fetch_assoc($result);
 
$f1=mysql_result($result,"lname");
$f2=mysql_result($result,"fname");
$f3=mysql_result($result,"oname");
$f4=mysql_result($result,"department");
 
$i++;
}
echo("<p> Welcome".$f1);
echo ("<p>Department:".$f3);
?>
I want to echo out a record specific to the current user but this error:

mysql_numrows(): supplied argument is not a valid MySQL result resource on line 25. Where line 25=
"$num=mysql_numrows($result);"

Please McInfo, Tg, and Jack could you guys give a possible insight as to what could be wrong?
ben.artiss
Forum Contributor
Posts: 116
Joined: Fri Jan 23, 2009 3:04 pm

Re: mysql_numrows(): supplied argument is not a valid MySQL

Post by ben.artiss »

Hey tobimichigan :) just a slight mistake is all.

Change:

Code: Select all

$query=mysql_query("Select * From user_table where pfno='$pfno'") or die (mysql_error());
To:

Code: Select all

$query="Select * From user_table where pfno='$pfno'";
Your getting a result of a result by the looks of it - hope that works.

Regards, Ben
tobimichigan
Forum Commoner
Posts: 48
Joined: Sun May 10, 2009 1:35 pm

Re: mysql_numrows(): supplied argument is not a valid MySQL

Post by tobimichigan »

Here's my code now:

Code: Select all

<?php
$pfno=$_GET["pfno"];
$query=mysql_query("Select * From user_table where pfno='$pfno'");
$result=mysql_query($query);
 
$num=mysql_num_rows('$result',$link) or die(mysql_error());
echo "<p> PFNO : ".$_SESSION["pfno"]. "<p>Logged in:  " .date("m/d/Y", $_SESSION["valid_time"]);
$i=0;
while ($i < $num) {
 
$pfno = mysql_fetch_assoc($result);
 
$f1=mysql_result($result,"lname");
$f2=mysql_result($result,"fname");
$f3=mysql_result($result,"oname");
$f4=mysql_result($result,"department");
 
$i++;
}
echo("<p> Welcome".$f1);
echo ("<p>Department:".$f3);
?>
But this ugly error:

"Warning: Wrong parameter count for mysql_num_rows() in on line 25
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #5' at line 1"

Line 25 being:
$num=mysql_num_rows('$result',$link) or die(mysql_error());

What could be wrong now?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: mysql_numrows(): supplied argument is not a valid MySQL

Post by aceconcepts »

Remove $link from mysql_num_rows(). If anything, $link should be placed as the second parameter in mysql_query().

Instead of posting your errors each time you encounter an error take a look at the PHP manual.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: mysql_numrows(): supplied argument is not a valid MySQL

Post by califdon »

tobimichigan wrote:

Code: Select all

$query=mysql_query("Select * From user_table where pfno='$pfno'");
$result=mysql_query($query);
What could be wrong now?
As was previously pointed out, you are trying to run the same query twice, the second time using a resource pointer instead of an SQL statement. To run a query, only use the mysql_query() function ONCE.
Post Reply