devan Posted November 23, 2011 Share Posted November 23, 2011 Hi guys, for the life of me, what am I doing wrong, I cannot figure out this one, getting this error : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ......... search.php on line 36 my code : $start = ($page-1)*$per_page; $sql = "SELECT productId, productCode, image, name, price, stock_level FROM inventory WHERE productCode LIKE '%".$searchp."%' OR name LIKE '%".$searchp."%' AND Seller_ID = '" . $_SESSION['SESS_SELL_ID'] . "' order by name limit $start,$per_page"; $rsd = mysql_query($sql); <?php while($row = mysql_fetch_array($rsd)) // ERROR OCCURS HERE : line 36 { $idpc=$row['productId']; $idc=$row['productCode']; $idi=$row['image']; $idn=$row['name']; $idp=$row['price']; $ids=$row['stock_level']; ?> all help appreciated as always. Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/ Share on other sites More sharing options...
cunoodle2 Posted November 23, 2011 Share Posted November 23, 2011 My guess is that this code is OUTSIDE of the "<?php" bracket.. "$start = ($page-1)*$per_page; $sql = "SELECT productId, productCode, image, name, price, stock_level FROM inventory WHERE productCode LIKE '%".$searchp."%' OR name LIKE '%".$searchp."%' AND Seller_ID = '" . $_SESSION['SESS_SELL_ID'] . "' order by name limit $start,$per_page"; $rsd = mysql_query($sql);" Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1290671 Share on other sites More sharing options...
devan Posted November 23, 2011 Author Share Posted November 23, 2011 My guess is that this code is OUTSIDE of the "<?php" bracket.. "$start = ($page-1)*$per_page; $sql = "SELECT productId, productCode, image, name, price, stock_level FROM inventory WHERE productCode LIKE '%".$searchp."%' OR name LIKE '%".$searchp."%' AND Seller_ID = '" . $_SESSION['SESS_SELL_ID'] . "' order by name limit $start,$per_page"; $rsd = mysql_query($sql);" Hi, no, the code in within the PHP tags, I only wish it was that easy ! :'( Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1290680 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2011 Share Posted November 23, 2011 If you search for (the keywords in) that error message, you will find that it generally means that your query failed due to an error of some kind. There are a couple of other possibilities, depending in what your actual code is (it always pays to post enough of your actual code the reproduces the problem.) For debugging purposes, use the following for your mysql_query statement - $rsd = mysql_query($sql) or die("Query failed: $sql<br />Error: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1290704 Share on other sites More sharing options...
devan Posted November 23, 2011 Author Share Posted November 23, 2011 Hi, I added the code you provided ( thanks ) to check the error, this is what MySQL error I get : Query failed: SELECT productId, productCode, image, name, price, stock_level FROM CubeCart_inventory WHERE productCode LIKE '%gold%' OR name LIKE '%gold%' AND Seller_ID = '25' order by name limit -35, 35 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-35, 35' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1290820 Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2011 Share Posted November 23, 2011 A negative number in the LIMIT clause is invalid. $page is either empty, non-existent, or a zero. You must always validate/limit data that you put into query statements. Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1290842 Share on other sites More sharing options...
devan Posted November 24, 2011 Author Share Posted November 24, 2011 Thank you for your help, I located the problem with your code and fixed it, all sorted Quote Link to comment https://forums.phpfreaks.com/topic/251666-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1290986 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.