views:

65

answers:

5

The exact error message is:

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 'where rfflag='0'' at line 1

Hi,

I'm trying to get some php scripts working and it dies with the above error message. There are two locations where rfflag is used in the SQL query:

$_SESSION['lang']=$objTerm->my_get_one("select min(id) from "
    .$objTerm->TABLE['languages']." where status='1' and rfflag='0'");

$rs_lang=$objTerm->execute_query("select id,language from "
    .$objTerm->TABLE['languages']." where `status`='1' and `rfflag`='0'");

How do I determine which one is causing the problem? Or is the problem something else altogether?

+2  A: 

Echo this:

"select id,language from ".$objTerm->TABLE['languages']." where status='1' and rfflag='0'"

and this:

"select min(id) from ".$objTerm->TABLE['languages']." where status='1' and rfflag='0'"

Then run execute each output in your favorite sql developer tool. Errors will be displayed there.

sheeks06
+1  A: 

How do I determine which one is causing the problem?

Remove one of the queries. See if it still happens.

On a secondary thought, I would suggest that you change your MySQL query code so, that it doesn't use die() to print out the error message. Use trigger_error or exceptions instead, this way you will automatically get a trace of which line caused it.

Jani Hartikainen
A: 

you just need to include space for where string in your queries,otherwise where will get cancatenated to your table name. like this

select * from tablewhere something=1

modify where string like this, " where ...." observe the space introduced.

srinivas reddy thatiparthy
THere is a space present.
tzmatt7447
A: 

How do I determine which one is causing the problem?

use trigger_error() to output an error message.
I guess (I have to guess because you supply no code) that you are using die() to output an error.
if you change this bad practice function to trigger_error(), you will be able to see the line number, where error occurred.
If you add non only mysql_error() to it's output, but also query itself, you will be able to see the problem code too.

Col. Shrapnel
A: 

I guess $objTerm->TABLE['languages'] is undefined or does not have the value you’re expecting.

As sheeks06 has already suggested, just echo the query to see if everything is as expected:

$query = "select min(id) from "
    .$objTerm->TABLE['languages']." where status='1' and rfflag='0'";
echo $query;
$_SESSION['lang']=$objTerm->my_get_one($query);

$query = "select id,language from "
    .$objTerm->TABLE['languages']." where `status`='1' and `rfflag`='0'";
echo $query;
$rs_lang=$objTerm->execute_query($query);
Gumbo