1.11M Members

Error Message - Array is Boolean, Not a Resource

 
0
 

So I'm getting this error message from MYSQL when I load this page. The first message is what's it displaying on the PHP code, the 2nd message is the result of mysql_error().

(1) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in [I][redacted][/I] on line 19

(2) 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 'AND CigarID = 334 AND DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= DateAdded' at line 1

When I run the query in mySQL it returns a result, as it should. So I'm not sure what's going on here. I've check to make sure the variable wasn't recycled and it's not. Any ideas what's going on here? Here's the offending code --

//Check User's Last Review
$SQL = "SELECT COUNT(CigarID) FROM reviews_cigar WHERE UserID = $UserID AND CigarID = $CigarID AND DATE_SUB(CURDATE(),INTERVAL 15 DAY) <= DateAdded";
$Result = mysql_query($SQL);
$row = mysql_fetch_array($Result) or die(mysql_error());
if( $row[0] > 0 ){
$errormsg = "Sorry but you have submitted a review for this Cigar in the past 15 days";
 
1
 

mysql_query returns a boolean false when the query fails so if you fix the query (to which the second error applies) the first will disappear also.

As for the second error: it's probably something to do with $UserID as the rest looks alright.
Maybe you could show us what the query looks like when it's executed? (echo $SQL)

 
0
 

mysql_query returns a boolean false when the query fails so if you fix the query (to which the second error applies) the first will disappear also.

As for the second error: it's probably something to do with $UserID as the rest looks alright.
Maybe you could show us what the query looks like when it's executed? (echo $SQL)

That was it, I forgot to bring over the $UserID variable - doh! :|

Thanks for the help!

Question Answered as of 3 Years Ago by Insensus
 
0
 

I Have a problem with syntax error on the following code

$myregion = $_POST['region'];
echo $myregion;
$names = mysql_query("SELECT * FROM course_name WHERE Region=$myregion");

while($row = mysql_fetch_array($names)) {
echo $row['Name_of_Course'], " " , $row['Region'], " " , $row['Price'],"<br>";
}

error is fetch_array expectects parameter 1 to be resource, boolean given on line 47

This code worked fine if I hard coded the Where condition but once I have put the $variable in, i get the error?

Could nyone help as I am new to php mysql

 
0
 
$query = "SELECT Name,Mobile,Website,Rating FROM grand_table order by 4";


// Passing Variables to execute and check

$result = mysql_query($query);

while( $data = mysql_fetch_array($result))
{
  echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td></tr>");

 }

To solve up the parameter and boolean error i had used above query

Also you can parse up value directly in the query ...

If you had any query you can contact me at : http://www.gfxdevelopers.com , My Id there : Gears.of.Codes

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: