User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,547 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,652 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 96727 | Replies: 43
Reply
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 31
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

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

  #1  
Jun 12th, 2004
[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 8:23 pm. Reason: had to include data forgotten.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Rep Power: 12
Solved Threads: 2
Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

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

  #2  
Jun 12th, 2004
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.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 31
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

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

  #3  
Jun 12th, 2004
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.
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Rep Power: 7
Solved Threads: 6
Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

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

  #4  
Jun 13th, 2004
That's usually best. Saves a lot of hassle.
Reply With Quote  
Join Date: Apr 2004
Location: Tracy
Posts: 743
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Rep Power: 7
Solved Threads: 31
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

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

  #5  
Jun 13th, 2004
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 11:51 am. Reason: :):)
!!!!! WARNING YOUR COMPUTER MAY BE INFECTED WITH SPYWARE!!!! PAY AN OVER PRICED AMMOUNT TO HAVE SOMTHING FIXED WE PLACED THERE IN THE FIRST PLACE!!!!!!!!!

sound familiar, know how to block yourself and keep yourself clean.
_____________________
http://www.lavasoftusa.com/ -->adaware
http://www.safer-networking.org/en/index.html -->spybot S&D
http://www.javacoolsoftware.com/spywareblaster.html -->spywareblaster
http://www.javacoolsoftware.com/spywareguard.html -->spywareguard
_____________________
and dont forget to spread the reputation to those that deserve!
Reply With Quote  
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Rep Power: 12
Solved Threads: 2
Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

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

  #6  
Jun 13th, 2004
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.


Originally Posted by Killer_Typo
i plan on posting it in the snipits area.
Yes, definitely. I'm sure people will find it helpful!
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
Reply With Quote  
Join Date: Mar 2007
Posts: 1
Reputation: civuk is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
civuk civuk is offline Offline
Newbie Poster

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

  #7  
Mar 9th, 2007
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
Reply With Quote  
Join Date: Apr 2007
Posts: 1
Reputation: lexid2002 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
lexid2002 lexid2002 is offline Offline
Newbie Poster

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

  #8  
Apr 29th, 2007
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
Reply With Quote  
Join Date: Dec 2006
Location: syria
Posts: 156
Reputation: w_3rabi is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

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

  #9  
Apr 30th, 2007
Originally Posted by civuk View Post
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 ???
Reply With Quote  
Join Date: Feb 2007
Location: Palmerston North, New Zealand
Posts: 16
Reputation: WhiteLeo is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
WhiteLeo's Avatar
WhiteLeo WhiteLeo is offline Offline
Newbie Poster

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

  #10  
May 1st, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC