【发布时间】:2026-02-14 16:55:01
【问题描述】:
示例:以下查询在字段中给我 Quotes 错误 -> GET['email']
mysql_query(" select * from user_info where user_mail = '$_GET['email']' ")
【问题讨论】:
-
不管走哪条路,请考虑SQL注入问题!
示例:以下查询在字段中给我 Quotes 错误 -> GET['email']
mysql_query(" select * from user_info where user_mail = '$_GET['email']' ")
【问题讨论】:
你可能想先转义字符串:
$_GET['email'] = mysql_real_escape_string($_GET['email']);
然后:
mysql_query(" select * from user_info where user_mail = '" . $_GET['email'] . "' ");
这些点将字符串放在一起。
【讨论】:
使用这样的赞誉。
mysql_query(" select * from user_info where user_mail = '{$_GET['email']}' ")
另外,请确保转义您的用户输入。您当前的设置看起来很容易受到 SQL 注入的影响。使用http://php.net/manual/en/function.mysql-real-escape-string.php 清理您的用户输入(如 $_GET 值)
【讨论】:
如果您已经在双引号字符串中,则关联数组字段名称不需要引号:
$str = "Hello $_GET[email].";
【讨论】:
$str = "Hello ".$_GET['email']; 恕我直言,这有助于易读性。
"Hello {$_GET['email']}" 或 "Hello {$_GET["email"]}"。
这样使用:
$SQL = "SELECT * FROM user_info WHERE user_mail = '".$_GET['email']."'";
mysql_query($SQL);
但我强烈建议对$_GET['email'] 采取一些安全措施,如下所示:
$email = mysql_real_escape_string($_GET['email']);
$SQL = "SELECT * FROM user_info WHERE user_mail = '".$email."'";
mysql_query($SQL);
【讨论】: