Page 1 of 2
Error: Query was empty
Posted: Thu Jun 28, 2007 3:46 pm
by seth_web
Hi,
I am having MySQL problem, Error: Query was empty.
It happens in every case. Here is my code.
Code: Select all
if ($sort2 = "bklt" ) {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND 'lb' = type OR 'sb' = type";
}
elseif ($sort = "t") {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND 't' = type";
}
elseif ($sort = "p") {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND 'p' = type";
}
elseif ($sort = "trt") {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND 't' = type OR 'sb' = type OR 'lb' = type";
}
elseif ($sort = "spainish") {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND 'Spainish' = Spainish";
}
elseif ($sort = "pdf") {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND '$sort2' = pdf";
}
elseif ($sort = "t") {
$querry1 = "SELECT * FROM mountzion
WHERE '$sort' = author AND 't' = type";
}
What do you think my problem is?
Posted: Thu Jun 28, 2007 3:50 pm
by feyd
Is there a reason your if's are using an assignment instead of a comparison?
Posted: Thu Jun 28, 2007 4:52 pm
by seth_web
Thank you. I missed that.
Posted: Thu Jun 28, 2007 6:05 pm
by ReverendDexter
And is it intentional that your variable is the column name instead of the value?
If it's not behaving as you expect, you may have your WHERE/AND/OR clauses backwards.
And if it's still not behaving how you'd expect, make sure you throw parentheses around groups of AND/OR statments you mean to have together, specifically that "WHERE '$sort' = author AND 't' = type OR 'sb' = type OR 'lb' = type" bit.
Hope it helps!
Posted: Thu Jun 28, 2007 6:08 pm
by feyd
ReverendDexter wrote:And is it intentional that your variable is the column name instead of the value?
I'm pretty sure that is perfectly valid.
Posted: Thu Jun 28, 2007 8:31 pm
by seth_web
Thanks all for your help.
Although I am still having problems.
Any other suggestions?
Posted: Thu Jun 28, 2007 8:44 pm
by superdezign
seth_web wrote:Thanks all for your help.
Although I am still having problems.
Any other suggestions?
You'll need to tell us what the problems are.
Posted: Fri Jun 29, 2007 7:47 am
by seth_web
I am getting, Error: Query was empty.
Posted: Fri Jun 29, 2007 7:48 am
by feyd
Unfortunately, that doesn't mean anything to us without context. We don't have a context at this point. You need to post more of your code.
Posted: Fri Jun 29, 2007 9:25 am
by seth_web
Here is the form.
Code: Select all
echo " <form action='main.php'>
<INPUT TYPE=RADIO NAME='sort2' VALUE='t' >Tracts<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='bklt' >Booklet<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='trt' >trt & bkit<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='p' >Paperback<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='spainish' >Spainish<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='pdf' >Downloads<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='fav' >Fav. Tract<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='classics' >Classics<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='ref' >Ref. Today<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='' >All<BR>
<INPUT TYPE=RADIO NAME='sort2' VALUE='fgb'>FGB<P>
<INPUT TYPE=SUBMIT VALUE='Submit'> <br> <br> ";
And here is my output.
Code: Select all
$result1 = MYSQL_QUERY($querry1) or DIE ('Error: '.mysql_error ());
echo "<table border='2' cellspacing='6' cellpadding='6'>
<tr>
<td>Code</td>
<td>Type</td>
<td>Author</td>
<td>Title</td>
<td>Spanish</td>
<td>Pages</td>
<td>Cost</td>
<td>Topic</td>
<td>PDF</td>
<td>Comments</td>
</tr>";
while ($list1 = mysql_fetch_array($result1, MYSQL_NUM)) {
echo "
<tr>
<td>"; echo "$list1[0]"; echo "</td>
<td>"; echo "$list1[1]"; echo "</td>
<td>"; echo "$list1[2]"; echo "</td>
<td>"; echo "$list1[3]"; echo "</td>
<td>"; echo "$list1[4]"; echo "</td>
<td>"; echo "$list1[5]"; echo "</td>
<td> $"; echo "$list1[6]"; echo "</td>
<td>"; echo "$list1[7]"; echo "</td>
<td>"; echo "$list1[8]"; echo "</td>
<td>"; echo "$list1[9]"; echo "</td>
</tr>";
}
echo "</table>";
Posted: Fri Jun 29, 2007 9:41 am
by Gente
Put
before
Code: Select all
$result1 = MYSQL_QUERY($querry1) or DIE ('Error: '.mysql_error ());
and post the result.
Posted: Fri Jun 29, 2007 9:44 am
by seth_web
I get the same results.
Posted: Fri Jun 29, 2007 9:55 am
by Gente
If your result is the same then your query is empty

Otherwise your have to see your query before error. So this is your problem. Check the place where $querry1 is assigned
Posted: Fri Jun 29, 2007 10:04 am
by seth_web
That is just the thing. I do not think that my "if" statements are working, but I
do not know why.
Posted: Fri Jun 29, 2007 10:14 am
by idevlin
Ok then, put
Just before the if statement, and tell us what is says.