PHP 搜索引擎注意事项:未定义索引:类别 [英] PHP search engine Notice: Undefined index: category

查看:37
本文介绍了PHP 搜索引擎注意事项:未定义索引:类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我在某个类别中浏览的帮助下制作了一个脚本示例:我们有下一个类别的 PCgames、All 和 Documents.X 用户正在 PCgames 中搜索 Y 游戏.并且脚本在PCgames类别中搜索Y游戏并显示所有结果.但是当用户单击搜索按钮时,服务器会显示下一个错误注意:未定义索引:第 5 行 search.php 中的类别HTML代码

Hi guys I have made a script with some help who browse in a category Example: We have next categorie PCgames, All and Documents. X user is searching in PCgames for Y game. And the script is saerching in PCgames ategory for Y game and display the all results. But when the user click on search button the server display next error Notice: Undefined index: category in search.php on line 5 HTML code

    <form action="search.php" method="POST">
<p><br />
<input name="q" type="hidden" />
<font color="black">Hunt Data:</font>
<input type="text" style="width: 180px" name="qfront" id="name" />
<select name="category">
<option value="0" id="all">All</option>
<option value="1" id="PCgames">PC-Games</option>
<option value="2" id="Console">Console</option>
<option value="3" id="Movies">Movies</option>
<option value="4" id="Music">Music</option>
<option value="5" id="XXX">XXX</option>
<option value="6" id="Windows">Windows</option>
<option value="7" id="Linux">Linux</option>
<option value="8" id="Software">Software</option>
<option value="9" id="Documents">Documents</option>
</select>
<input type="submit" value="Search" />
</p>
</form>

search.php 文件

search.php file

    <?php
//define each directory here, the index starts with 0 == all and so on.
$categorydir = array('/Category/All/', '/Category/PCGames/', '/Category/Documents/');
//if option selected and its valid number
if($_POST['category'] && ctype_digit($_POST['category'])){    //line 5
 if(array_key_exists($_POST['category'], $categorydir) && is_dir($categorydir[$_POST['category']])){
   $handle = opendir($categorydir[$_POST['category']]);
 }else{
   echo 'target directory not found';
 }
}else{
 //please enter an option
}
?>

对于注意事项的一些帮助:未定义索引:第 5 行 search.php 中的类别?

Some help for Notice: Undefined index: category in search.php on line 5 ?

推荐答案

if(isset($_POST['category']) {
 if(ctype_digit($_POST['category']) && isset($categorydir[$_POST['category']])){

 }
}

和你的数组

 $categorydir = array('/Category/All/', '/Category/PCGames/', '/Category/Documents/');

有 3 个条目,但您的表单有 10 只猫.

have 3 entries, though your form have 10 cats.

这篇关于PHP 搜索引擎注意事项:未定义索引:类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆