printf Error - argument is not a valid MySQL result resource

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
okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

printf Error - argument is not a valid MySQL result resource

Post by okelly »

Code below is working fine in Apache,PHP4,MySQL on Win2k.
I'm getting Warning: mysql_result(): supplied argument is not a valid MySQL result resource when running on the live Unix Server.

The error is coming from the printf statement (second line from bottom below)
Can anybody indicate how to fix it. Thanks
Conor O'Kelly

---------------------------------
<?php
$ArticleID = $_GET['ArticleID'] ;
$result = mysql_query("SELECT articles.ArticleID, articles.Article, articles.ShortTitle FROM articles WHERE ArticleID='$ArticleID' ",$db);
echo "<table border=0 width=800 cellspacing=0 cellpadding=0>
<tr>
<td width=800 bgcolor=#FFCC00><img border=1 src=../images/banner2.jpg></td>
</tr>
</table>" ;
echo "<table border=0 width=800 height=100% cellspacing=0 cellpadding=0 valign=top align=left>
<tr>
<td width=171 valign=top rowspan=2 bgcolor=ffffcc><p>&nbsp;&nbsp;</p></td>
<td width=598 height=6% valign=top>&nbsp;<p>You are at: <a href=../index.htm>home</a>><a href=okelly01.php?ArticleID=56>clanns</a>><a href=okelly03.php?ArticleID=55>okelly</a></td>
<td width=32</td>
</tr>
<tr>
<td width=600 valign=top align=left> ";
echo "<h1>";
printf(" %s<br>\n", mysql_result($result,0,"ShortTitle"));
echo "</h1>";
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Your error is actually here

Code: Select all

$result = mysql_query("SELECT articles.ArticleID, articles.Article, articles.ShortTitle FROM articles WHERE ArticleID='$ArticleID' ",$db);

try this

Code: Select all

echo ((!$result) ? 'Mysql says: '.myql_error() : '');
put that right after your query
okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

Warning: mysql_result(): supplied argument is not a valid My

Post by okelly »

Ok...

Mysql says: No database selected

So i guess it's in the config.php or the upload on to the mySQL server (??)
I'll check with ISP that I've correctly uploaded the data from the test server to the live server...

Is this correct?

thanks for your help
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

okelly
Forum Commoner
Posts: 29
Joined: Thu Feb 23, 2006 2:18 pm

Post by okelly »

cool thnx :D

it's reporting "not connected"....
i'll have a closer look at the server setup & make sure i got it right
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

mysql_connect()

a little rtfm goes a long way :wink:
Post Reply