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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.