tmyonline Posted November 7, 2007 Share Posted November 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/ Share on other sites More sharing options...
aschk Posted November 7, 2007 Share Posted November 7, 2007 What's on line 61? Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-386939 Share on other sites More sharing options...
atlanta Posted November 7, 2007 Share Posted November 7, 2007 Yea post up some of your code so we can tell you , Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-386950 Share on other sites More sharing options...
tmyonline Posted November 7, 2007 Author Share Posted November 7, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-386995 Share on other sites More sharing options...
revraz Posted November 7, 2007 Share Posted November 7, 2007 Looks like something is wrong with your Arguement, like $gradeResult Echo it and see if it holds the data you expect. Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-386999 Share on other sites More sharing options...
tmyonline Posted November 7, 2007 Author Share Posted November 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-387033 Share on other sites More sharing options...
revraz Posted November 7, 2007 Share Posted November 7, 2007 See if adding a @ will surpress it @mysql_fetch_assoc($gradeResult); Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-387037 Share on other sites More sharing options...
pocobueno1388 Posted November 7, 2007 Share Posted November 7, 2007 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()); Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-387042 Share on other sites More sharing options...
tmyonline Posted November 7, 2007 Author Share Posted November 7, 2007 Hi revraz: Yes, your recommendation in suppressing the warning messages using "@" works. Thank you very much. Tommy Quote Link to comment https://forums.phpfreaks.com/topic/76411-solved-mysql-problem-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-m/#findComment-387114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.