I trying to query a database to find relevant results between two columns in separate tables, to do this I’m using the following code:
$query = "SELECT * FROM $table WHERE MATCH (TITLE) AGAINST ($description) AND ARTIST=$band ORDER BY relevance DESC";
$result = mysql_query($query);
if (!$result) {
die("Result False on line 47: $result <br>
Query: $query <br>
Error: " . mysql_error());
}
As you might expect the error message appears saying I have an error in my MYSQL syntax but I’m not sure what it is, any pointers?
AGAINST ($description)should beAGAINST ('$description')ARTIST=$bandshould beARTIST='$band'Any strings that are processed through queries need single quotes ( ‘ ) around them, and column names with spaces need backticks ( ` ).
If
$descriptionor$bandcontain any quotes or slashes you will need to escape them using mysql_real_escape_string() (I’d recommend doing this anyway)Also, you can consolidate your
diestatement into your query line: