-4

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...!?

Rick Bross
  • 1,060
  • 3
  • 16
  • 39

2 Answers2

3

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.

MaX
  • 1,765
  • 13
  • 17
1

You are calling the query:

mysql_query($cityQry)

But your query variable is named $townQuery.

It should be:

mysql_query($townQuery)
Bad Wolf
  • 8,206
  • 4
  • 34
  • 44