TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-08-2010, 04:09 PM   #1 (permalink)
The Visitor
 
Join Date: Sep 2010
Location: Norway
Posts: 3
Thanks: 2
Calus is on a distinguished road
Default Mysql_num_rows(): supplied argument is not a valid MySQL result resource

Hey guys, some weekend fun for us all.

I'm trying to setup a simple script to display a MySQL database tables contents, in a table. My intention is for the table to dynamically add new rows as more information is added to the database.

This is the file that should display the database info. It shows the table headers, and the Mysql_num_rows(): error message.

According to my research that shouldn't happen as long as database and username connection checks out.

Anyone have an idea?

Code:
<body>

<?php 

// Kobler til databasen 

mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// Bygger foresp?rsel
$query = mysql_query("SELECT * FROM `database table`") or die(mysql_error());

$result = mysql_query($query);
$num = mysql_num_rows($result);
?>
	
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">ID</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Level</font></th>
<th><font face="Arial, Helvetica, sans-serif">Class</font></th>
<th><font face="Arial, Helvetica, sans-serif">Reference</font></th>
<th><font face="Arial, Helvetica, sans-serif">Why join?</font></th>
<th><font face="Arial, Helvetica, sans-serif">Previous guilds</font></th>
<th><font face="Arial, Helvetica, sans-serif">Experience</font></th>
<th><font face="Arial, Helvetica, sans-serif">Contact ingame</font></th>
<th><font face="Arial, Helvetica, sans-serif">Contact SWTOR</font></th>
<th><font face="Arial, Helvetica, sans-serif">Contact e-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">Accepted policy</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail address</font></th>
</tr>

<?php
$i=0;
while ($i < $num) {
	
$ID=mysql_result($result,$i,"ID");
$appname=mysql_result($result,$i,"appname");
$applvl=mysql_result($result,$i,"applvl");
$appcla=mysql_result($result,$i,"appcla");
$appref=mysql_result($result,$i,"appref");
$appwhy=mysql_result($result,$i,"appwhy");
$apprev=mysql_result($result,$i,"apprev");
$appexp=mysql_result($result,$i,"appexp");
$coning=mysql_result($result,$i,"coning");
$conswm=mysql_result($result,$i,"conswm");
$conemail=mysql_result($result,$i,"conemail");
$policy=mysql_result($result,$i,"policy");
$email=mysql_result($result,$i,"email");

?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $ID; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $appname; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $applvl; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $appcla; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $appref; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $appwhy; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $apprev; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $appexp; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $coning; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $conswm; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $conemail; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $policy; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $email; ?></font></td>
</tr>

<?php
$i++;
}
?>
</table>
</body>
</html>
Can someone please help me find out what is wrong here? I just don't see it yet.
Send a message via MSN to Calus
Calus is offline  
Reply With Quote
Old 10-08-2010, 04:35 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

That error 99.9% of the time means the query you ran didnt work. Check your SQL for error by using "or die mysql_error();" after the mysql_query command
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
Calus (10-11-2010)
Old 10-10-2010, 06:40 PM   #3 (permalink)
Only Human
 
Join Date: Oct 2010
Posts: 5
Thanks: 0
GSmith is on a distinguished road
Default

Actually, 100% of the time it means the function was not passed a valid MySQL result resource. This error should narrow it down to whatever is being passed to mysql_num_rows; in this case, $result.

The problem is found in the second call to mysql_query.
PHP Code:
$query mysql_query("SELECT * FROM `database table`") or die(mysql_error());

$result mysql_query($query);
$num mysql_num_rows($result); 
$query holds a result set.
$result ultimately will always be FALSE, since the second call to mysql_query is being passed a resource $query where it expects a string argument. As Village Idiot mentioned, checking for errors after the second call to mysql_query would confirm this.

$query is an inappropriate variable name for a result set. Rename $query to $result and get rid of the second call to mysql_query.

Here's what I end up with after the changes:
PHP Code:
mysql_connect("localhost""username""password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$result mysql_query("SELECT * FROM `database table`") or die(mysql_error());
$num mysql_num_rows($result);

... 
I hope my explanation is elaborate enough.

Cheers.
GSmith is offline  
Reply With Quote
The Following User Says Thank You to GSmith For This Useful Post:
Calus (10-11-2010)
Old 10-11-2010, 12:10 AM   #4 (permalink)
The Visitor
 
Join Date: Sep 2010
Location: Norway
Posts: 3
Thanks: 2
Calus is on a distinguished road
Default

I can't believe I didn't see that. But I guess most will feel that way after getting their newbie mistakes pointed out to them.

Thank you both for your help, the script is now working as intended and the mistake I made has been noted down so I'll learn from it for the future.
Send a message via MSN to Calus
Calus is offline  
Reply With Quote
Old 10-18-2012, 12:44 PM   #5 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
dashixiong is offline  
Reply With Quote
Old 10-22-2012, 09:06 AM   #6 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default Coach Outlet

You’ve relativelyCoach Outlet recently arrived in New Delhi after living in two of Asia’s other great cities,Coach Outlet Store Online Tokyo and Hong Kong, for several years. Do these cities feel like they’re part of the same continent? Yes, and no. In terms Coach Factory Onlineof infrastructure, they couldn’t be more different. Getting regularCoach Outlet power and water at my house in New Delhi is never a sure thing, even though Coach Purse Outlet OnlineI’m paying the same rent that I paid in Tokyo and almost the same electricity prices. Both Hong Kong and Tokyo are also crowded places,Coach Factory Outlet Online but both cities are incredibly well planned and efficiently run. Efficient is not a word I would use to describe my Coach Bags Outlet Onlineday-to-day life in New Delhi. On the other hand, one thing that I think Hong Kong and New Delhi have in common isCoach Handbags Outlet a shared sense of optimism — a feeling that the best is yet to come. That’s definitely not the feeling you get in Tokyo,Coach Outlet Online or in the U.S. when I go home. It’s a big part of what I find addictive about living and working in this part of the world. You feel like you’re watching the future unfold.
dashixiong is offline  
Reply With Quote
Old 01-29-2013, 11:33 AM   #7 (permalink)
The Addict
 
Join Date: Oct 2012
Posts: 244
Thanks: 0
dashixiong is on a distinguished road
Default

Organizers said Coach Outlet Online was opportune because the battle’s 150-year anniversary is in December, and Fredericksburg Coach Factory Outlet has been preparing to mark the sesquicentennial. in the new agreement is that Coach Outlet Online revolutionary councils from 14 Syrian provinces now each have a representative, though not all live Coach Online Outlet in Syria. The hope is that will bind the coalition to those inside the country. Perhaps Coach Bags Outlet the most important body the new group is expected to form is a Revolutionary Military Council Coach Factory Online to oversee the splintered fighting organizations and to funnel both lethal and nonlethal Coach Factory Outlet military aid to the rebels. It should unite units of the Free Syrian Army, various militias Coach Outlet Store Online and brigades in each city and large groups of defectors. Before the ink was even dry on the Coach Outlet Store final draft, negotiators hoped that it would bring them the antiaircraft missiles they crave to Coach Factory Stores take on the Syrian Air Force. The United States and Britain have offered only Coach Handbags Outlet nonmilitary aid to the uprising. A similar attempt by the Syrian National Council to Coach Factory Store supervise the military never jelled. Organizers said funding was too haphazard. Eventually foreign Coach Factory Online governments like Qatar and Saudi Arabia, which are financing and arming the rebels, found Coach Factory Online their own favorite factions to deal with. Foreign leaders notably including Secretary of State Coach Outlet Hillary Rodham Clinton urged this unification largely so they could coordinate their Coach Factory Outlet efforts and aid through a group of technocrats. Once it receives international recognition, the Coach Outlet Store Online coalition is supposed to establish a temporary Coach Outlet Online military never jelled.
dashixiong is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning: fread(): supplied argument is not a valid stream resource sarmenhb General 7 04-23-2008 08:48 AM
Securing your MySQL Queries with Sprintf Wildhoney General 26 03-18-2008 06:52 PM


All times are GMT. The time now is 05:50 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design