Max Max - 4 months ago 9
PHP Question

Php Mysql query not working when adding AND parameter with >=

I am trying to get my php script to output the name of a row in my mysql database. I know the issue is with the long >= '$Slong'. The long value in the datase is a float. The Slong value is set to 1.11 and there is a row that has the long value at 1.21.

I believe this is where the problem lies:

$Slong = $long - 0.01;
$result = mysql_query("SELECT name FROM locations WHERE age < '$age' AND aTime = 'Morning' AND long >= '$Slong'");

Answer

Long is reserved keyword, so use backticks around:

$Slong = $long - 0.01;
$result = mysql_query("SELECT name FROM locations WHERE age < '$age' AND aTime = 'Morning' AND `long` >= '$Slong'");
Comments