Jump to content

php is not working with MySQL - can't add AND


jeger003

Recommended Posts

hello,

here is my query

 

$this->sql_query = "SELECT * FROM ".$this->classifieds_table."
WHERE category ".$this->in_statement." AND live=1 ";

the above works....but when I add {AND location = "".$_COOKIE["State"]."\"} - it doesnt work

 

no matter what location equals it wont read query. as soon as i remove the extra AND it works.

 

 

help please

The syntax for just the part you are adding should be -

AND location = '".$_COOKIE["State"]."'

 

Resulting in the whole query of -

 

$this->sql_query = "SELECT * FROM ".$this->classifieds_table."
WHERE category ".$this->in_statement." AND live=1 AND location = '".$_COOKIE["State"]."'";

EDIT: Beaten to it :)

 

$this->sql_query = sprintf("SELECT * FROM %s WHERE category = '%s' AND live=1 AND location = '%s'", $this->classifieds_table
                                                                                                  , $this->in_statement
                                                                                                  , mysql_real_escape_string($_COOKIE["State"])
                          );

 

If your query is still failing you can get the error message using mysql_error function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.