2013-03-27 98 views
0

這是我在我的數據庫中搜索框的編碼,但是當我運行它時它顯示錯誤注意:未定義變量:在第15行的/opt/lampp/htdocs/1234.php中搜索 然後ii在我的搜索框中輸入任何內容 它表示 找不到對象!php中的搜索框創建

在此服務器上找不到請求的URL。推薦頁面上的鏈接似乎是錯誤或過時的。請通知該頁面的作者關於錯誤。

如果您認爲這是服務器錯誤,請與網站管理員聯繫。

錯誤404

本地主機 的Apache/2.4.3(UNIX)的OpenSSL/1.0.1c PHP/5.4.7

<html> 
    <h2>Search</h2> 
    <form name="search" method="post" action="<?=$PHP_SELF?>"> 
    Seach for: <input type="text" name="find" /> in 
    <Select NAME="field"> 
    <Option VALUE="fname">diseasename</option> 
    <Option VALUE="lname">genename</option> 
    </Select> 
    <input type="hidden" name="searching" value="yes" /> 
    <input type="submit" name="search" value="Search" /> 
    </form> 
    </html> 
    <?php 
    //This is only displayed if they have submitted the form 
    if ($searching =="yes") 
    { 
    echo "<h2>Results</h2><p>"; 

    //If they did not enter a search term we give them an error 
    if ($find == "") 
    { 
    echo "<p>You forgot to enter a search term"; 
    exit; 
    } 

    // Otherwise we connect to our Database 
    mysql_connect("localhost", "root", "****") or die(mysql_error()); 
    mysql_select_db("missensencemuttation") or die(mysql_error()); 

    // We preform a bit of filtering 
    $find = strtoupper($find); 
    $find = strip_tags($find); 
    $find = trim ($find); 

    //Now we search for our search term, in the field the user specified 
    $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); 

    //And we display the results 
    while($result = mysql_fetch_array($data)) 
    { 
    echo $result['fname']; 
    echo " "; 
    echo $result['lname']; 
    echo "<br>"; 
    echo $result['info']; 
    echo "<br>"; 
    echo "<br>"; 
    } 

    //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
    $anymatches=mysql_num_rows($data); 
    if ($anymatches == 0) 
    { 
    echo "Sorry, but we can not find an entry to match your query<br><br>"; 
    } 

    //And we remind them what they searched for 
    echo "<b>Searched For:</b> " .$find; 
    } 
    ?> 

我不知道我做錯了什麼在我的腳本。而我在PHP初學者,我使用爲獲得在php.can一個知識解決此腳本

回答

0

使用如下的互聯網參考:

extract($_POST); 
if ($searching =="yes") 
+0

謝謝suresh,但是當我點擊搜索按鈕這是什麼它顯示對象沒有找到! 在此服務器上找不到請求的URL。推薦頁面上的鏈接似乎是錯誤或過時的。請通知該頁面的作者關於錯誤。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。 錯誤404 本地主機 的Apache/2.4.3(UNIX)的OpenSSL/1.0.1c PHP/5.4.7 – 2013-03-27 10:22:42

0

$searching沒有在這一刻腳本中定義。我想你的意思是$_POST['searching']

添加if (isset($_POST['searching'])) { //old if }各地的比較,以確保$_POST['searching']設置和替換$searching$_POST['searching']

編輯:更換$PHP_SELF$_SERVER['PHP_SELF'],這可以幫助你。

+0

更改爲$ _ SERVER後[ 'PHP_SELF']它在主頁上它的自我 – 2013-03-27 10:43:51

+0

然後將其更改爲你想發送數據的文件。例如'action =「search_results.php」'。目前,它再次將數據發送到當前文件。 – 2013-03-27 10:47:25