Jump to content

slight sql problem


JamesThePanda

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/259987-slight-sql-problem/
Share on other sites

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
}

Link to comment
https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332573
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332580
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/259987-slight-sql-problem/#findComment-1332600
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.