0

我正在用 PHP 为我的网站创建一个搜索工具。基本上我有两个单选按钮,一个标记为“用户”,另一个标记为“主题”,其想法是用户将能够在我的网站中搜索用户或主题。

这是搜索表单的代码:

<form name = "search" action = "search_result.php" method = "get" style = "float:right;">
<input type = "text" name = "query" id = "query" maxlength = "100">
<br />
<p><label for = "user">Search users
      <input type = "radio" name = "options" id = "user" value = "user">
  </label>
 <label for = "topics">&nbsp;Search topics
    <input type = "radio" name = "options" id = "topics" value = "topics">
 </label></p>
<input type = "Submit" value = "Go">
</form>

我试过这种方法:

if($_GET['user']==checked)//Base on specific radiobutton and check if checked

我也试过这个:

if($_GET['options']=="users")//Base on grouped radiobuttons

但两者都没有奏效。如何检查 PHP 已检查了哪个按钮?回答时,请记住我没有使用 jQuery 的经验。

4

4 回答 4

3

你检查为

if($_GET['options']=="users")

虽然价值似乎user如此,但只需将其更改为

if($_GET['options']=="user")

或以其他方式将您的字段的值更改为users.

于 2013-05-16T12:35:11.547 回答
1

请记住,如果未选中,复选框和单选按钮将不会在提交时发送任何内容。一旦检查,他们将发送一个值,如果指定的话,或者只是on. 所以,你需要这样检查:

if($_GET['options']== "user")

检查用户单选按钮是否选中或

if($_GET['options']== "topics") 

检查主题是否已检查。

请记住,提交时仅传递名称,它将用作 中的键$_GET$_POST$_REQUEST

于 2013-05-16T12:35:51.440 回答
1

这个 shd 工作

if($_GET['options']=="user")


not


users
于 2013-05-16T12:36:04.863 回答
1

使用这个条件,它一定会为你工作

if($_GET['options']=='user'){

}
于 2013-05-16T12:45:32.623 回答