JamesThePanda Posted March 30, 2012 Share Posted March 30, 2012 Hi I have been getting this error. mysql_fetch_array() expects parameter 1 to be resource, boolean given Its driving me mad I know its something really simple. Can anyone see what it is? mysql_select_db("product", $con); $sqlout = mysql_query("SELECT * FROM 'tblt' WHERE 'UID' =('$ids')"); while($sqlres = mysql_fetch_array($sqlout)) Thanks James Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/ Share on other sites More sharing options...
chriscloyd Posted March 30, 2012 Share Posted March 30, 2012 Question why are you putting () around your var? Where are you setting the var $ids? try this <?php $sqlout = mysql_query("SELECT * FROM `tblt` WHERE `UID` = '{$ids}'"); while ($sqlres = mysql_fetch_assoc($sqlout)) { //you can use assoc or array //I just like using assoc } Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332573 Share on other sites More sharing options...
JamesThePanda Posted March 30, 2012 Author Share Posted March 30, 2012 here is were im setting the variable $ids = $_POST['uid']; Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332574 Share on other sites More sharing options...
chriscloyd Posted March 30, 2012 Share Posted March 30, 2012 Okay well did you try the code i posted? Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332579 Share on other sites More sharing options...
DavidAM Posted March 30, 2012 Share Posted March 30, 2012 The mysql_query function returns a resource when a SELECT statement succeeds. When an action query (INSERT, UPDATE, DELETE) succeeds, it returns true (a boolean), when any query fails, it returns false (a boolean). When a mysql_whatever() function issues that message, it generally means the query failed. To figure out why a query failed, you can do this: mysql_select_db("product", $con); $sql = "SELECT * FROM 'tblt' WHERE 'UID' =('$ids')"; $sqlout = mysql_query($sql); if ($sqlout === false) { print('Query: ' . $sql . ' failed with error: ' . mysql_error()); exit; } while($sqlres = mysql_fetch_array($sqlout)) Of course, in a production environment, you would do something more user-friendly than just exiting -- and you really don't want to display that kind of information to potential hackers. The problems I see with that query are: 1) You have the table name in quotes -- that is not valid 2) You have parenthesis aroud the $ids value -- I really don't know if that hurts or not, but I don't see any need for it. Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332580 Share on other sites More sharing options...
batwimp Posted March 30, 2012 Share Posted March 30, 2012 You also need to sanitize your input from your POST. Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332585 Share on other sites More sharing options...
JamesThePanda Posted March 30, 2012 Author Share Posted March 30, 2012 Hi I made some adjustments to the code, $ids = $_POST['uid']; $con = mysql_connect("localhost","root",""); mysql_select_db("product", $con); $sqlout = mysql_query("SELECT * FROM `product2` WHERE `ID` IN ('$ids')"); while ($sqlres = mysql_fetch_assoc($sqlout)) { echo $sqlres['filename'] . " " . $sqlres['title']; } mysql_close($con); Im wondering why it isnt echoing the results? Any thoughts Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332600 Share on other sites More sharing options...
JamesThePanda Posted March 30, 2012 Author Share Posted March 30, 2012 Okay well did you try the code i posted? Yes Chris, that solved tht problem but a new one has poped up. Thank you for your help its much appreciated Thanks James Quote Link to comment https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332606 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.