MasterACE14 Posted July 15, 2010 Share Posted July 15, 2010 I have the following code... if(!isset($_POST['img'])) $_POST['img'] = null; if(!$_POST['img']) die("not a valid product!"); $_POST['img'] =mysql_real_escape_string($_POST['img']); $img = end(explode('/',$_POST['img'])); $row = mysql_query("SELECT * FROM `ca_shop` WHERE `img`='".$img."'"); $row = mysql_fetch_array($row); if(mysql_num_rows($row) == 0) die("There is no such product!"); The value of 'img' is plugins/shopping-cart/img/products/iPod.png and I'm getting the following errors... <b>Warning</b>: mysql_query() expects parameter 2 to be resource, null given in <b>shop.php</b> on line <b>7</b><br /> <br /> <b>Warning</b>: mysql_fetch_array() expects parameter 1 to be resource, null given in <b>shop.php</b> on line <b>8</b><br /> <br /> <b>Warning</b>: mysql_num_rows() expects parameter 1 to be resource, null given in <b>shop.php</b> on line <b>10</b><br /> There is no such product! I have no idea why? appreciate the help, Thanks Link to comment https://forums.phpfreaks.com/topic/207840-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
kenrbnsn Posted July 15, 2010 Share Posted July 15, 2010 You're reusing the variable $row, and you're not checking to make sure that your query was syntactically correct. Try this: <?php $q = "SELECT * FROM `ca_shop` WHERE `img`='".$img."'"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); if(mysql_num_rows($rs) == 0) die("There is no such product!"); $row = mysql_fetch_array($rs); ?> Ken Link to comment https://forums.phpfreaks.com/topic/207840-expects-parameter-1-to-be-resource/#findComment-1086522 Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2010 Share Posted July 15, 2010 Are you sure you're connecting to the db successfully? EDIT: What ken said, too . . . My first thought when I see those errors is the connection hasn't been made . . . Link to comment https://forums.phpfreaks.com/topic/207840-expects-parameter-1-to-be-resource/#findComment-1086523 Share on other sites More sharing options...
MasterACE14 Posted July 15, 2010 Author Share Posted July 15, 2010 after those adjustments Ken I'm now getting... <b>Warning</b>: mysql_query() expects parameter 2 to be resource, null given in <b>shop.php</b> on line <b>7</b><br /> Problem with the query: SELECT * FROM `ca_shop` WHERE `img`='iPod.png'<br> also that query in PHPMyAdmin works. Link to comment https://forums.phpfreaks.com/topic/207840-expects-parameter-1-to-be-resource/#findComment-1086532 Share on other sites More sharing options...
MasterACE14 Posted July 15, 2010 Author Share Posted July 15, 2010 Are you sure you're connecting to the db successfully? EDIT: What ken said, too . . . My first thought when I see those errors is the connection hasn't been made . . . sorry for wasting your time, completely missed the obvious, this file is called via an AJAX request on another page and I thought the database connection on that page would also be the same as this file called with the AJAX request, thrown in a database connection now and it's working. Thanks again for the help! Link to comment https://forums.phpfreaks.com/topic/207840-expects-parameter-1-to-be-resource/#findComment-1086541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.