943,749 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 249224
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 12th, 2004
0

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Expand Post »
[php]
<?php
/* declar some relevant variables */
$Host = "localhost"; //location of mySQL on server
$User = "michael"; //my username
$Pass = "koolaide"; //my password
$Name = "phpaccess"; //name of the database to be used
$Table = "info"; //name of the table within the database

mysql_connect ($Host, $User, $Pass, $Name, $Table) or die ("unable to connect to database");
mysql_select_db("$Name") or die ("unable to select DB");
$sqlquery = "SELECT * FROM $table WHERE opinion = 'is greate'";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result); //LINE NUMBER 23

$i = 0;
if ($number < 1)
{
echo "<center><p>There were no results for your search</p></center>";
}
else
{
while ($number > $i)
{
$thename = mysql_result ($result, $i, "name");
$theemail = mysql_result ($result, $i, "email");
echo "<p><b>Name:</b></p> $thename<br /><b>E-Mail:</b>$theemail</p>";
$i++;
}
}
?>[/php]

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\www\databaseconnect.php on line 23
i get that error, ive commented line number twentythree. this is just a database tutorial that im working on and i hope that maybe someone can tell me whats goin on.

o and dont worry about the username password stuff, this server will never go online, this is all practice stuff.

(line twenty three is in reference to the entire php file, this is only part of it, i left out the <html> tags part)
Last edited by Killer_Typo; Jun 12th, 2004 at 9:23 pm. Reason: had to include data forgotten.
Similar Threads
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jun 12th, 2004
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

You defined the variable "$Table" with a capital T, yet you try to interpolate it in the querystring with a lower case "t." PHP is case sensitive for user defined variables.
Team Colleague
Reputation Points: 262
Solved Threads: 18
a.k.a inscissor
samaru is offline Offline
1,227 posts
since Feb 2002
Jun 12th, 2004
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

wow thanks that fixed it, but im not sure if i got the output i am supposed to get. though i plan on working on this a little more. thanks for the help i didnt even notice that. maybe from now i should just try to work with my variables in lowercase.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jun 13th, 2004
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

That's usually best. Saves a lot of hassle.
Team Colleague
Reputation Points: 63
Solved Threads: 6
Supreme Evil Overlord
Roberdin is offline Offline
282 posts
since Feb 2003
Jun 13th, 2004
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

now im very happy! i have a submit form which writes to a database, a submitted form which displays what has just been submitted, and a database forms which displays all information that has been submitted.

i plan on posting it in the snipits area.
Last edited by Killer_Typo; Jun 13th, 2004 at 12:51 pm. Reason: :):)
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jun 13th, 2004
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Quote originally posted by Killer_Typo ...
wow thanks that fixed it, but im not sure if i got the output i am supposed to get. though i plan on working on this a little more. thanks for the help i didnt even notice that. maybe from now i should just try to work with my variables in lowercase.
Glad you were able to get it working! Yeah, I usually keep my variables lower case. The only place I use capital letters are in classes.


Quote originally posted by Killer_Typo ...
i plan on posting it in the snipits area.
Yes, definitely. I'm sure people will find it helpful!
Team Colleague
Reputation Points: 262
Solved Threads: 18
a.k.a inscissor
samaru is offline Offline
1,227 posts
since Feb 2002
Mar 9th, 2007
0

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

I am having the same problem
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Abyss Web Server\htdocs\getrecord.inc on line 6
how ever this is my code


<?php
// version 1.1
$qstr = "SELECT * from members where id = '1' ";
$result = mysql_query($qstr);

if (mysql_num_rows($result)) // check login info is correct
{
$username = mysql_result($result,0, "username");
$password = mysql_result($result,0, "password");
echo "<b>The username:</b> $username<br>";
echo "<b>The password:</b> $password<br>";
}
else echo "ERROR - unable to find current username and password!";
mysql_close();
?>

please someone help me
Reputation Points: 10
Solved Threads: 0
Newbie Poster
civuk is offline Offline
1 posts
since Mar 2007
Apr 29th, 2007
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

I have this problem and i am new so please go slow...

error on page

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/loyalist/public_html/shop/pages/0.php on line 17

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/loyalist/public_html/shop/pages/0.php on line 13

--------

<?php
//
// TYPES:
//
// CDS DVDS CLOTHING KEYRINGS/BOTTLEOPENERS FLAGS OFFERS TICKETS
//
// 1 2 3 4 5 6 7
//
$query = "SELECT * FROM config WHERE id=3";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$query = "SELECT * FROM items WHERE id=".$row['value']." ORDER BY id DESC Limit 0,1";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$id = $row['id'];
$name = $row['name'];
$desc = $row['description'];
$price = $row['price'];
$img = $row['img'];
$menu = $row['menu'];
$frase = $desc;
$char = 180;
$desc = checklenght($frase, $char);

$content = $namet.$name.$desct.$desc.$pricet.'£'.$price;

?>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" rowspan="2" class="image" align="center"><a href="#" onclick="window.open('info.php?id=<?php print $id ?>&menu=<?php print $menu; ?>', '_info', 'HEIGHT=500,resizable=no,WIDTH=430,scrollbars=1');"><img src="images/item_enlarge.gif" border="0" /></a><br/><br/><img src="products/<?php print $img; ?>" width="95" height="95" border="0" /></td>
<td valign="top" class="item-main"><b><?php print $content; ?></b></td>
</tr>
<tr>
<td valign="top"><img src="images/item_order1.gif" border="0" /><a href="#" onclick="window.open('info.php?id=<?php print $id ?>&menu=<?php print $menu; ?>', '_info', 'HEIGHT=500,resizable=no,WIDTH=430,scrollbars=1');"><img src="images/item_order2.gif" border="0" /></a></td>
</tr>
</table>
<br />
<?php
}
}
?>
<b>Welcome...</b></span>
<br />
<br />
<span style="font-size: 14px; ">
<?php
$query = "SELECT * FROM config WHERE id=1";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
$introtext = $row['value'];
$introtext = nl2br($introtext);
print $introtext;
?>
</span></b>


hope someone can help

lexi
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lexid2002 is offline Offline
1 posts
since Apr 2007
Apr 30th, 2007
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Click to Expand / Collapse  Quote originally posted by civuk ...
I am having the same problem
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\Abyss Web Server\htdocs\getrecord.inc on line 6
how ever this is my code


<?php
// version 1.1
$qstr = "SELECT * from members where id = '1' ";
$result = mysql_query($qstr);

if (mysql_num_rows($result)) // check login info is correct
{
$username = mysql_result($result,0, "username");
$password = mysql_result($result,0, "password");
echo "<b>The username:</b> $username<br>";
echo "<b>The password:</b> $password<br>";
}
else echo "ERROR - unable to find current username and password!";
mysql_close();
?>

please someone help me
you should check the id field type is it int or varchar ???
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
May 1st, 2007
0

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

For those who got a error with the num rows, I suggest you add the error dispaly for the sql error message.

if(!$result){die(mysql_error();}

Stick that below the query, it will give a specific message about what is wrong with the query. There isn't a problem with the num_rows function usually, but with the actual query itsself.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
WhiteLeo is offline Offline
16 posts
since Feb 2007

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.
This thread is currently closed and is not accepting any new replies.
Previous Thread in PHP Forum Timeline: pagination within image - IF problem
Next Thread in PHP Forum Timeline: Name variable after other variable





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


Follow us on Twitter


© 2011 DaniWeb® LLC