我有一个脚本,它是我编写的,用于根据uniqueID查找ID
if ($_REQUEST['uniqueId'] != ""){
$qA = "SELECT id FROM customerdata WHERE uniqueId = \"". $_REQUEST['uniqueId']."\"";
$rA = mysql_query($qA);
list($id) = mysql_fetch_row($rA);
echo $id;
exit;
if ( mysql_num_rows ($rA) > 0) {
header('Location:response-en.php?id=$id');
}
else
{
header('Location:not-found.php');
}
}它不是将用户发送到response-en.php?id=1,而是将它们发送到response-en.php?id=$id
你知道为什么会发生这种事吗?任何帮助都将不胜感激!谢谢!
发布于 2011-08-25 04:23:06
用法:header('Location:response-en.php?id='.$id);
使用单引号时的:'
这是一个字符串文字。该字符串中的所有内容(我是指所有内容)都是批发的。如果执行了以下操作:$something = 'Location:response-en.php?id=$id';,则$something的值为:Location:response-en.php?id=$id为了将变量添加到字符串中,需要使用连接操作符.。因此,在$something = 'Location:response-en.php?id='.$id;之后,$something的值将是Location:response-en.php?id=5 (假设$id = 5),请参见:http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
使用双引号时的:"
PHP会在你的sting内部搜索任何变量。然后,它将用变量的值替换变量名。如果你这样做:$something = "Location:response-en.php?id=$id";,$something的值是:Location:response-en.php?id=5 -注意双引号的使用。请参阅:http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
另外,我想补充的是,您的脚本容易受到SQL-injection attack的攻击。在SQL查询中使用查询字符串值之前,请始终对其进行清理。有关清理sql的值的更多信息,请参阅mysql_real_escape_string的文档。
发布于 2011-08-25 04:23:09
单引号字符串中的变量不会被解析。双引号内的变量是。查看:
发布于 2011-08-25 04:23:09
您需要使用双引号来处理字符串中的变量。不是单引号。
https://stackoverflow.com/questions/7181772
复制相似问题