2013-02-25 130 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