2013-02-25 69 views
1

嗨,大家好我已经编写了一个脚本,帮助他们浏览类别 示例:我们有下一个类别PCgames,All和Documents。 X用户在PC游戏中搜索Y游戏。并且该剧本在PC游戏中为Y游戏而兴奋并显示所有结果。 但是,当用户在搜索按钮,单击该服务器显示下一个错误注意:未定义指数:类别中的search.php第5行 HTML代码PHP搜索引擎注意:未定义的索引:类别

<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中的类别?

+2

尝试'if(isset($ _ POST ['category'])...)'而不是。 – 2013-02-25 17:38:49

+0

尝试改进您的原始帖子:http://stackoverflow.com/questions/15056015/php-search-function-in-a-category如果你这样做,它可以重新打开。 – 2013-02-25 17:38:53

+0

致命错误:无法在第5行的search.php的写入上下文中使用函数返回值 – 2013-02-25 18:45:08

回答

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

} 
} 

和您的阵列

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

有3项,虽然你的表单中有10只猫。

+0

谢谢。此脚本正在工作,但他不显示结果... – 2013-02-25 18:53:08