Here is my code:
<?php
$_SETTINGS = $GLOBALS["_SETTINGS"];
$trigger = $_SETTINGS->fields->trigger->value;
echo $trigger . " = " . $_GET[$trigger] . "</br>";
$townQry = "SELECT * FROM towns WHERE id = '" . $_GET[$trigger] . "'";
echo $townQry . "</br>";
$result = mysql_query($cityQry) or die('Could not retreive towns: ' . mysql_error());
while ($town = mysql_fetch_assoc($result)) {
echo $town["town_name"];
}
?>
This is what it is echoing out:
town_id = 2
SELECT * FROM towns WHERE id = '2'
Could not retreive towns: Query was empty
Isn't the SQL valid...!?
You use $cityQry
in your query, but the query is in $townQry
.
$result = mysql_query($townQry) or die('Could not retreive towns: ' . mysql_error());
Additional
Your query is wide open to sql injection, I'd advice you to Google prepared statements.
You are calling the query:
mysql_query($cityQry)
But your query variable is named $townQuery
.
It should be:
mysql_query($townQuery)