error with mysql_fetch_assoc()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alexia Moon

    #1

    error with mysql_fetch_assoc()

    I have downloaded a Wordpress template E commerce theme. One of the features of the template is that I can select a piece of clothing and adjust it's price using the 'add_attributes ' tag. When I do that, it seems to work perfectly until I get to the part where I have to add inventory amount and I get this error message

    Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in /homepages/11/xxxxxx/htdocs/xxxxxx/xxxxxx/wordpress/wp-content/themes/xxxxxx/lib/engine/backend_actions .php on line 1712
    The lady that created this website is trouble shooting it for me but I also need to find out information for myself too.

    Here is the code
    Code:
    function display_attributes_data($meta_value,$order_by_clause){
    
    	$table		= is_dbtable_there('inventory');
    	$qStr		= "SELECT * FROM $table WHERE ID_item = '$meta_value' $order_by_clause"; // ORDER BY
    	$res 		= mysql_query($qStr);							
    
    	$data		= NULL;
    
    		while($row = mysql_fetch_assoc($res)){
    			
    				$data .= "<tr>";
    				
    				foreach($row as $k => $v){
    					if($k != 'iid' && $k != 'ID_item' && $k != 'amount' && !empty($v)){
    						$data .= "<td>$v</td>";
    					}			
    				}
    				
    				$data .= "<td><input type='text' name='$row[iid]' value='$row[amount]' /></td></tr>";
    		}
    
    return $data;
    }

    Can anyone help me please? I am building a baby store and want this up by Feb. I have tons of stock to add on here and it is delaying the process.
    Last edited by Dormilich; Nov 7 '10, 09:24 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the reason is simple (because it’s the #1 problem when working with MySQL): your query fails and mysql_query() returns false which in turn is not the right parameter type for mysql_fetch_ass oc().

    you must always check the return values of each of your mysql_* functions (or use PDO in Exception mode)

    like
    Code:
    $r = mysql_query($sql) or die(mysql_error());
    PS. your code is open to SQL Injection.

    Comment

    Working...