Jump to content

[SOLVED] MySQL problem: Warning: mysql_fetch_assoc(): supplied argument is not a valid M


tmyonline

Recommended Posts

Dear all,

 

My PHP program displays this error

 

"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\htdocs\Test\index.php on line 61"

 

I don't see anything wrong with my syntax or logics; my program works fine as expected although this error appears on the top of the output everytime.  Any idea on how to get rid of this error or hide it ?

 

Thanks a lot!

Tommy

The error occurs on lines 61, 65, 70, 74, 79:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\htdocs\Test\index.php on line 61

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\htdocs\Test\index.php on line 65

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\htdocs\Test\index.php on line 70

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\htdocs\Test\index.php on line 74

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\htdocs\Test\index.php on line 79

 

 

Here's a portion of my code where the problem arises:

 

 

$max = 21569;

  if (!isset($_POST['request']) || isset($_POST['submit'])) {

    do {

      $_SESSION['n'] = rand(1, $max);

      $m = $_SESSION['n'];

 

                $imgSQL      = "SELECT * FROM loc_item WHERE LOC_key = $m";

                $imgResult  = mysql_db_query($db,$imgSQL,$cid);

                $imgRow      = mysql_fetch_assoc($imgResult);

 

                $expSQL      = "SELECT * FROM experiences_loc_item_jn WHERE LOC_key = $m";

                $expResult  = mysql_db_query($db,$expSQL,$cid);

                $expRow      = mysql_fetch_assoc($expResult);

                $EXPERIENCES = $expRow['experiences'];

 

                $gradeSQL    = "SELECT * FROM experiences WHERE experiences_key = $EXPERIENCES";

                $gradeResult = mysql_db_query($db,$gradeSQL,$cid);

(line 61)      $gradeRow    = mysql_fetch_assoc($gradeResult);

 

                $subjSQL    = "SELECT * FROM experiences_subjects_jn WHERE experiences_key = $EXPERIENCES";

                $subjResult  = mysql_db_query($db,$subjSQL,$cid);

(line 65)      $subjRow    = mysql_fetch_assoc($subjResult);

                $SUBJECT    = $subjRow['subject'];

 

                $subNameSQL    = "SELECT * FROM subject WHERE subject_key = $SUBJECT";

                $subNameResult = mysql_db_query($db,$subNameSQL,$cid);

(line 70)      $subNameRow    = mysql_fetch_assoc($subNameResult);

 

                $teacherKeySQL    = "SELECT * FROM experiences_teachers_jn WHERE experiences_key = $EXPERIENCES";

                $teacherKeyResult = mysql_db_query($db,$teacherKeySQL,$cid);

(line 74)      $teacherKeyRow    = mysql_fetch_assoc($teacherKeyResult);

                $TEACHERKEY      = $teacherKeyRow['teacher'];

 

                $teacherSQL    = "SELECT * FROM teachers WHERE teachers_key = $TEACHERKEY";

                $teacherResult = mysql_db_query($db,$teacherSQL,$cid);

(line 79)      $teacherRow    = mysql_fetch_assoc($teacherResult);

 

    } while (($imgRow['image'] == "") || ($gradeRow['gradeused'] == "") || ($subNameRow['name'] == "") || ($teacherRow['f_name'] == "") ||            ($teacherRow['l_name'] == ""));

  }

 

 

Many thanks guys!

Yes, I echoed it and it held the data I expect.  My program works fine though.  It's just that, somehow, these warnings appear on the top of the output.  How can I remove or hide these warning messages ?

 

Thanks.

Tommy

Why would you want to suppress the errors instead of fixing them?

 

Add a die statement to the end of each query

 

EX

$imgResult   = mysql_db_query($db,$imgSQL,$cid)or die(mysql_error());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.