PHP未定义索引 [英] PHP Undefined Index
问题描述
我已经创建了一个名为query_age的选择框,其中包含一个名为query_age的选择框。我的html表单:
< form method =getaction =user_list.php>
< select name =query_age>
< option value =>无关紧要< / option>
<选项值=在18和30之间> 18 - 30< / option>
< option value =31和40之间> 31 - 40< / option>
< option value =41与50之间> 41 - 50< / option>
<选项值=在51和60之间> 51 - 60< / option>
< option value =61和70之间> 61 - 70< / option>
<选项值=在71和80之间> 71 - 80< / option>
<选项值=在81和90之间> 81 - 90< / option>
< option value => 90>年龄大于90< / option>
< / select>
在相应的php表单中,我有:
$ query_age = $ _GET ['query_age'];
当我运行该页面时,出现此错误:
注意:未定义的索引:第19行的index.php中的query_age
I don我不知道为什么会这样,我很想知道如何让它消失。
t看到php文件,但可能是这样 -在您的php文件中替换:
$ query_age = $ _GET ['query_age'];
附带:
$ query_age =(isset($ _ GET ['query_age'])?$ _GET ['query_age']:null);
大多数情况下,您第一次运行脚本时不需要?query_age = [某些东西]
和 $ _ GET
没有类似于 query_age
的关键字。
This is going to sound really stupid, but I cannot figure out why I am getting this error.
I have created a selection box, named "query_age" in my html form:
<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>
In the corresponding php form, I have:
$query_age = $_GET['query_age'];
When I run the page, I get this error:
Notice: Undefined index: query_age in index.php on line 19
I don't understand why this is happening, and I'd love to know how to make it go away.
I don't see php file, but that could be that -
replace in your php file:
$query_age = $_GET['query_age'];
with:
$query_age = (isset($_GET['query_age']) ? $_GET['query_age'] : null);
Most probably, at first time you running your script without ?query_age=[something]
and $_GET
has no key like query_age
.
这篇关于PHP未定义索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!