Thread7 Posted April 7, 2008 Share Posted April 7, 2008 I get an error where running a query. I done this type of thing many many times so I don't know why this particular one is giving me trouble. The query is inside a loop so it runs 6 times. Every time PHP spits out this warning: --- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in MyPHPPage.php on line 74. --- But the weirdest thing is that the query runs fine. Because my script shows values that are obtained from this query without any problem. I've seen other posts in this forum where the programmer has a similar error, but none where it is just a warning and the script is executing fine. Here is the pertinent area of code. ...... $entryid = $weekrow['entryid']; $pnsql = "SELECT pickname from entries where entryid=$entryid"; $pnresult = dbquery($pnsql); $pnrow = mysql_fetch_assoc($pnresult); //This is line 74 where it says I have a problem. echo $pnrow['pickname']; //This line executes just fine showing the correct value of the pickname entry in the table. ...... Thank you. Link to comment https://forums.phpfreaks.com/topic/99990-crazy-error-supplied-argument-is-not-a-valid-mysql-resource/ Share on other sites More sharing options...
trq Posted April 7, 2008 Share Posted April 7, 2008 Whta does dbquery() return? Link to comment https://forums.phpfreaks.com/topic/99990-crazy-error-supplied-argument-is-not-a-valid-mysql-resource/#findComment-511316 Share on other sites More sharing options...
Thread7 Posted April 7, 2008 Author Share Posted April 7, 2008 Sorry. dbquery is just a way to show a friendly error message to users. I'll post the function below. Basically it should run mysql_query($pnsql); function dbquery($q,$req = true) { static $dbase = null; if ( !$dbase ) { $dbase = mysql_connect( DBHOST, DBUSER, DBPASS ); if ( $dbase ) { $status = mysql_select_db( DBNAME ); if ( !$status ) { $dbase = null; } } if ( !$dbase ) { if ( $req == true ) { require_once 'pages/ErrorPage.php'; $err = new ErrorPage(); $err->$errortext = ' <!-- mysql_error '.mysql_error().' --> The database is temporarily unavailable. '; $err->display(); exit; } else { return false; } } } return mysql_query($q); } Link to comment https://forums.phpfreaks.com/topic/99990-crazy-error-supplied-argument-is-not-a-valid-mysql-resource/#findComment-511338 Share on other sites More sharing options...
cooldude832 Posted April 7, 2008 Share Posted April 7, 2008 odds are you are returning the string "resource id #4" for example in your function instead of a link to said resource, thus you can't access the mysql resource made from the query and thus the error is true you don't have a valid mysql resource. Link to comment https://forums.phpfreaks.com/topic/99990-crazy-error-supplied-argument-is-not-a-valid-mysql-resource/#findComment-511343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.