【发布时间】:2018-08-14 06:10:20
【问题描述】:
我目前正在用 PHP 编写一个插件,我有一个列表框,其中包含从 1 到 30 的数字和一个“提交”按钮。插件页面正在运行一些 SQL 请求。
关键是当您在list box 中选择一个数字并单击提交按钮时,SQL 请求应该更新。
例如:
SELECT G.xxx
FROM yyy M,
zzz G
WHERE M.name = G.nomfield
AND G.nomfield = "xxx"
AND G.idfield = 01
AND G.xxx = $numberfrom1to30
点击提交按钮后,显示应根据list box中选择的数字不同。我该怎么做?
我尝试过:
<?php
$selected = isset( $_GET['numberfrom1to30'] ) ? $_GET['numberfrom1to30'] : "" ;
$selectedValue = 'selected="selected"';
?>
<?php
$numberfrom1to30= $_GET['numberfrom1to30'];
?>
但这是我的错误:Unknown column '$numberfrom1to30' in 'where clause'
【问题讨论】:
-
AND G.nomfield = "xxx" AND G.idfield = "01" AND G.xxx = "$numberfrom1to30".. 错过了引号 -
强制性:您可以接受注射。好的,关于主题,如果在错误中将变量名返回给您,则您不会转义字符串。
-
过滤变量 - php.net/manual/en/function.filter-var.php 或使用正则表达式或将变量转换为 int。