这听起来真的很愚蠢,但我无法弄清楚为什么我会收到这个错误.
我在我的html表单中创建了一个名为"query_age"的选择框:
<form method="get" action="user_list.php">
<select name="query_age">
<option value="">Doesn't matter</option>
<option value="between 18 and 30">18 - 30</option>
<option value="between 31 and 40">31 - 40</option>
<option value="between 41 and 50">41 - 50</option>
<option value="between 51 and 60">51 - 60</option>
<option value="between 61 and 70">61 - 70</option>
<option value="between 71 and 80">71 - 80</option>
<option value="between 81 and 90">81 - 90</option>
<option value="> 90">Older than 90</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在相应的PHP表单中,我有:
$query_age = $_GET['query_age'];
Run Code Online (Sandbox Code Playgroud)
当我运行页面时,我收到此错误:
注意:未定义的索引:第19行的index.php中的query_age
我不明白为什么会这样,我很想知道如何让它消失.
Rad*_*kel 93
我没有看到php文件,但可能是 -
在你的php文件中替换:
$query_age = $_GET['query_age'];
Run Code Online (Sandbox Code Playgroud)
有:
$query_age = (isset($_GET['query_age']) ? $_GET['query_age'] : null);
Run Code Online (Sandbox Code Playgroud)
最可能的是,在你第一次没有运行脚本?query_age=[something],并$_GET有一个像没有密钥query_age.
在我看来,在分配之前检查会员的存在是非常难看的.
Kohana具有使选择参数简单的有用功能.
你可以这样做自己...
function arrayGet($array, $key, $default = NULL)
{
return isset($array[$key]) ? $array[$key] : $default;
}
Run Code Online (Sandbox Code Playgroud)
然后做一些像......
$page = arrayGet($_GET, 'p', 1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
231228 次 |
| 最近记录: |