【发布时间】:2014-08-29 19:20:36
【问题描述】:
我有一个包含多个 html 文本输入的表单,我想使用这些输入的值来进行一个搜索查询(例如,我希望它看起来像这样 results.php?input=value1+value2+value3)我试过了,但是我还没有设法得到一个查询来自 3 个输入字段的所有值的查询。
$input = $_GET['input']; //this is for the text input - ignore
$topic = $_GET['topic']; // the first select box value which works well
$location = $_GET['location']; //the second select box value which isn't being inserted into the query
$combined = $input . $topic . $location;
$terms = explode(" ", $combined);
$query = "SELECT * FROM search WHERE input='$input' AND topic ='$topic' AND location='$location' ";'
【问题讨论】:
-
用一个输入字段编写查询很容易。添加更多更容易:添加更多表单字段,将其数据导入 PHP,然后在查询中使用
and和/或or将where子句中的各个字段子句链接在一起。但这取决于你。我们不是来教你什么是基本的 PHP 和 SQL。 -
请向我们展示您尝试过的代码。如果您不向我们展示您已经完成的工作并具体告诉我们您遇到的问题,我们将无能为力。
-
$_GET['location']的值是多少? -
请打印所有变量的值。您的代码也容易受到SQL injection attack 的攻击。你应该使用MySQLi。