We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,099 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Error Message - Array is Boolean, Not a Resource

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";
3
Contributors
3
Replies
8 Months
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
jrotunda85
Junior Poster
145 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
Skill Endorsements: 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)

Insensus
Junior Poster
112 posts since Mar 2011
Reputation Points: 70
Solved Threads: 46
Skill Endorsements: 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!

jrotunda85
Junior Poster
145 posts since Feb 2011
Reputation Points: 19
Solved Threads: 7
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Insensus

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

cyd44
Newbie Poster
3 posts since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0674 seconds using 2.73MB