ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

PHP搜索引擎注意:未定义索引:类别

2019-10-13 01:32:34  阅读:216  来源: 互联网

标签:php search-engine


这个问题已经在这里有了答案:            >            “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP                                    28个
>            PHP search function in a category [closed]                                    2个
大家好,我在一些类别的帮助下制作了一个脚本
示例:我们有下一个PCgames,全部和文档. X用户正在PCgames中搜索Y游戏.该脚本在PCgames游戏中用于Y游戏,并显示所有结果.
但是,当用户单击搜索按钮时,服务器将显示下一个错误注意:未定义的索引:第5行中search.php中的类别
HTML代码

    <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文件

    <?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中的category?

解决方法:

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

 }
}

和你的数组

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

有3个条目,尽管您的表格有10只猫.

标签:php,search-engine
来源: https://codeday.me/bug/20191013/1904406.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有