这是我的代码:
<?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"];
}
?>
这就是它的回声:
town_id = 2
SELECT * FROM towns WHERE id = '2'
Could not retreive towns: Query was empty
SQL不是有效的......!?
答案 0 :(得分:3)
您在查询中使用$cityQry
,但查询位于$townQry
。
$result = mysql_query($townQry) or die('Could not retreive towns: ' . mysql_error());
其他强>
您的查询对sql注入很开放,我建议您使用Google准备好的语句。
答案 1 :(得分:1)
您正在调用查询:
mysql_query($cityQry)
但您的查询变量名为$townQuery
。
应该是:
mysql_query($townQuery)