War_Hero Posted October 13, 2008 Share Posted October 13, 2008 Hi all. I'm getting an error with one of my scripts...but the error doesn't seem to be within my actual script. Here's the error I'm getting: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /usr/home/*********/domains/*******/public_html/class/class_db_mysql.php on line 71 Now, the script I'm working on is called researchfund.php. I'll post the part of code that I'm working on that produces the error: function med_create1() { global $db,$ir,$userid; $select = ("SELECT * FROM `research_inv`"); $qselect = $db->query($select); $rowselect = $db->fetch_row($qselect); $_GET['ID'] = abs((int) $_GET['ID']); $q = ("SELECT * FROM `items` WHERE `itmid` = {$_GET['ID']}"); $itemd = $db->fetch_row($q); if($rowselect['r_invitemID'] != 96 AND $rowselect['r_invitemID'] != 97) { die("You don't have all of the materials needed to create this medicine. <a href = 'researchfund.php' />Go Back</a>"); } else { print "You have produced a large stash of Medicine 1. You can now distribute it around the community. <a href = 'researchfund.php' />Go Back</a>"; $med1 = sprintf("DELETE * FROM `research_inv` WHERE `r_invitemID` = '%d' AND `r_invitemID` = '%d'", 96, 97); $db->query($med1); $med1a = sprintf("INSERT INTO `research_inv` (r_invID, r_invitemID, r_invitemNAME, r_invitemPRICE) VALUES (%d, %d, %d, %d)", '', 102, $itemd['itmname'], $itemd['itmprice']); $db->query($med1a); } } Can anyone explain to me about why I'm getting this error and how to fix it? :) Any help will be highly appreciated. :) Quote Link to comment Share on other sites More sharing options...
Floydian Posted October 13, 2008 Share Posted October 13, 2008 Re: Error. Please help! Any time you use >>> $db->fetch_row You need to make sure the "resource" you pass into it is a valid resource (since the db class does not do that check for you) You used that Database method twice in the part of the script you posted. One of them is being passed an invalid resource. Most likely the value being passed is "false". Quote Link to comment Share on other sites More sharing options...
War_Hero Posted October 14, 2008 Author Share Posted October 14, 2008 Re: Error. Please help! Right...I think I understand you. :) So, what would be classed as valid? I don't understand why the part of my script that's causing the error is invalid, as I've used similar code in other scripts and they've worked fine. :? Thank you...for helping me. It's improving my knowledge and understanding. :) Quote Link to comment Share on other sites More sharing options...
Floydian Posted October 14, 2008 Share Posted October 14, 2008 Re: Error. Please help! Before you execute a line like: $db->fetch_row($q); Take the variable you pass into that, which in this case is $q and add in this bit of code: if($q === false) { echo mysql_error(); } Remember to put that before the $db->fetch_row($q);, and if $db->fetch_row($q); uses a different variable in the argument, such as $db->fetch_row($query);, you would replace $q in that if block with $query. See what that does. You likely have an error in a mysql_query somewhere. This code should tell you what that error is. And if that doesn't work, try this instead: if (!is_resource($q) ) { var_dump($q); } Same rules apply to that as the other if block. Put before the fetch array, use the variable passed to the fetch array. Quote Link to comment 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.