Error: (1065) Query was empty

I am using a if statement in my PHP code to determine which query should be run. Today I expanded this if/elseif statement to include a third possibility. However, when I load the page I get the following error:

MySQL error occurred. 
Error: (1065) Query was empty

I am able to echo the exact query to the page, as a debugging effort, and this exact same query can be copied and pasted in to mySQL Workbench and run perfectly. I searched on google for this error and some people said it may be due to an extra semicolon in my query, but I checked and that is no my issue.

Here is a snip of the actual code:

elseif ($_SESSION[complianceRole] == "Judge")  {
$getTestimonial = "

	date_format(dateAdded, '%m-%d-%Y') as dateAdded, 
	length(testimony) - length(replace(testimony, ' ', ''))+1 as length, 
	datediff(now(), u.lastLogin) AS sinceLogin 
FROM testimonies t, users u 
	t.uID = u.uID
	and classifyStatus is not null
	and reviewStatus is not null
	and classifyStatus <> reviewStatus
	and busy is null
	and bouncing = 'No'
	and datediff(now(), u.lastLogin) < 1460
	and u.uID not in (333, 717)
ORDER BY datediff(now(), u.lastLogin)



echo $_SESSION[complianceRole];
echo $getTestimonial;

$result = mysql_query($getTestimonial) or die("<p>Please email us the following information:</p> <p>Query: $getTestimonial </p> <p>Error:  mysql_errno() " . mysql_error() ); 

Can someone help me understand why the error says my query is empty?


Add an echo stating something like “This elseif has been run” to that elseif, if the new echo isn’t run then the query will be empty.

btw, you should really use the proper syntax when doing inner joins, you might want to also consider using the leading commas convention.

Semi-ontopic: You need to be aware that the old mysql_* extension is depreceated as of version 5.5 of PHP.

I have since added more debug code, like you suggested, and now I have verification that the correct elseif statement is being executed. Unfortunately I still get the error. Any other suggestions?


When you echo $getTestimonial do you get the query displayed?

And what does the CONSTANT

Thanks everyone for your help. Come to find out, the error message was not from this query, but one further down the PHP page involving an UPDATE. Ugh, it took forever to find and I’m glad it’s behind me now!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.