GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   SQL fetch Errors? (https://gfy.com/showthread.php?t=1094314)

Webmaster Advertising 12-27-2012 10:04 AM

SQL fetch Errors?
 
Could one of the programming types give me a hand with this error that i am getting running a script on my server...

Quote:

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/r3ading/public_html/admin/sets.php on line 175
Quote:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/r3ading/public_html/admin/sets.php on line 206
Here are the 2 lines of code it is telling me are faulty but i dont see *why* because the script works perfectly on another server...

174 & 175 line:
Code:

$query="SELECT COUNT(*) FROM $table_name";
list($total_links)=mysql_fetch_array(mysql_query($query));

203 to 207 lines:
Code:

$i=0;
$res=mysql_query($query);
echo "<td>";
while($r=mysql_fetch_array($res))
{
 $i++;
 $id=$r['id'];
 $dir_name=$r['dir_name'];
 $thumb=displayThumb($dir_name,$r['thumb']);

Any help you could offer would be appreciated, ive been on with my hosting tech support a few times about this but theyre telling me it a 'code' issue not a server issue, but i *know* for a fact this program works 100% on another server but they wont hear any of it :(

woj 12-27-2012 10:07 AM

$table_name is not defined, or that table doesn't exist at all, or is perhaps corrupted... or perhaps you have wrong db credentials in your config file...

if you want me to take a closer look for a few bucks, icq: 33375924 or woj#at#wojfun#.#com

AndrewX 12-27-2012 10:23 AM

Try backing up and restoring the database tables again. Also note that 'warning' messages can be turned off in PHP configuration (debug mode), they are not errors which will halt your script.

Webmaster Advertising 12-27-2012 10:34 AM

I just repaired the SQL table and that seems to have fixed it for a few minutes.

Im now thinking there is an issue with my hosting companies SQL system perhaps?

Every time i run the program, if i 'repair' the table afterwards it works again.

AndrewX 12-27-2012 11:08 AM

At those lines the warning appears, change mysql_fetch_array to @mysql_fetch_array

It will make it silent.

alcstrategy 12-27-2012 11:16 AM

Quote:

Originally Posted by AndrewX (Post 19392164)
At those lines the warning appears, change mysql_fetch_array to @mysql_fetch_array

It will make it silent.

you get the error because you dont check if the result is valid

what good is making it silent if he needs for debugging assuming its not a live site and if it is a live site then set display_errors off in php config and then check error log, but add some code to handle that issue checking the result var

Also you should move away from mysql library at the very least use mysqli. The Mysql lib will be deprecated in php's future and its an old library that lacks support in many things

Webmaster Advertising 12-27-2012 11:31 AM

Well after getting on the phone with the host, it appears the error was with them blocking the server IP address from writing to SQL.

No idea how or why this happened, but the problem is now fixed and the script is working as it should be.

Thanks all for the assistance with this issue, its appreciated :)

Nookster 12-27-2012 09:26 PM

You need to CAST the count to a named variable...

Code:

$query="SELECT COUNT(*) AS numrows FROM $table_name";
$ret = mysql_query($query);
$fetched = mysql_fetch_array($ret);
echo 'Amount = '.$fetched['numrows'];

That's some really horrible code, btw. :(

...glad you got it sorted out.


All times are GMT -7. The time now is 11:11 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123