2016-12-03 117 views
0

我一直在努力學習PHP一段時間的簡單的網站。我使用bootstrap製作了一個簡單的php表單。

我使用GET方法來從輸入到URL文本,它顯示了在此處顯示的URL的search.php: URL

文件結構: Screenshot of directories

對於一些原因,當我嘗試在search.php頁面上回顯值時,網頁是空白的。我可能犯了一個愚蠢的錯誤,所以任何幫助都會很棒!

的index.php代碼:

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 

    <title>Mc Report</title> 
    <meta name="description" content="Mc Report"> 
    <meta name="author" content="Cre8tionz"> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
    <link rel="stylesheet" href="css/styles.css"> 
    <link rel="stylesheet" href="css/bootstrap.css"> 
    <link rel="stylesheet" href="css/bootstrap-theme.css"> 
    <script> 
    $(function(){ 

     $(".dropdown-menu li a").click(function(){ 

     $(".but:first-child").text($(this).text()); 
     $(".but:first-child").val($(this).text()); 

    }); 

    }); 
    </script> 
</head> 

<body> 
    <div class="container container-table"> 
    <div class="row vertical-center-row"> 
     <div class="text-center col-lg-8 col-lg-offset-2"> 
     <div class="main-logo"> 
      <img src="img/logo.png"></img> 
     </div> 
      <div class="row"> 
      **<form action="search.php" method="get" novalidate="novalidate"> 
       <div class="col-lg-10"> 
       <div class="input-group"> 
        <input name="q" type="search" class="form-control" aria-label="..." placeholder="Search for a username"> 
        <div class="input-group-btn"> 
        <button type="button" class="but btn btn-default dropdown-toggle pull-right" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Catageory<span class="caret"></span></button> 
        <ul class="dropdown-menu dropdown-menu-right"> 
         <li><a href="#">Mc-Market Username</a></li> 
         <li><a href="#">Minecraft Username</a></li> 
         <li><a href="#">Minecraft UUID</a></li> 
        </ul> 
        </div> 
       </div> 
       </div> 
       <div class="col-lg-2"> 
       <div class="btn-group" role="group" aria-label="..."> 
        <button type="submit" class="btn btn-default">Search</button> 
       </div> 
       </div> 
      </form>** 
      </div> 
     </div> 
     <footer> 
     <div class="footer"> 
      <div class="container narrow row-fluid text-center navbar-fixed-bottom"> 
       <div class="col-lg-4"> 
       Mc Report 
       </div> 
       <div class="col-lg-4"> 
       About 
       </div> 
       <div class="col-lg-4"> 
       Copyright &copy; 2016 
       </div> 
      </div> 
     </div> 
     </footer> 
    </div> 
    </div> 
</body> 
</html> 

的search.php代碼:

<html> 
<body> 
<?php 
    if($_GET["q"]) { 
    print_r($_GET); 
    $searchquery = $_GET["q"]; 
    echo $searchquery; 
    } 
?> 
</html> 
</body> 
+0

您的代碼在* search.php *文件的環境中工作以除去除* php *代碼之外的html代碼。也刪除〜phpinfo()〜 – Karthi

+0

我認爲你是從文件打開該頁面,而不是從服務器(lampp,xampp,wamp ...)打開。 Php頁面必須由服務器首先處理 – Aleksandar

+0

@Aleksandar我在Xampp服務器上有它,但它仍然不能正常工作:https://i.gyazo.com/96ff60591c7dfbb3c6fc231e1360cad3.png – Cre8tionz

回答

0

您的網址爲file:/// ...
最有可能你正在打開您的本地文件在瀏覽器中。瀏覽器不能執行PHP腳本,因此它將整個PHP代碼視爲<和>作爲未知標籤。標籤不顯示,所以你看到一個空白頁面。

您需要一個網絡服務器來執行PHP腳本。
運行網絡服務器的最簡單方法是在項目根目錄(mcreport.net目錄)中運行php -S localhost:8001
然後在您的瀏覽器中打開http://localhost:8001/

+0

我忘了截圖Xampp文件路徑。我實際上是在一個網絡服務器上運行它,我只是傻,忘了顯示它。以下是路徑:https://i.gyazo.com/96ff60591c7dfbb3c6fc231e1360cad3.png – Cre8tionz

+0

在瀏覽器中打開頁面的源代碼。它是空的嗎? – justpusher

+0

檢查search.php請求的服務器狀態碼。您可以在Inspector(開發人員工具)中的Network選項卡中進行檢查。最有可能是200或500. 檢查PHP錯誤的xampp錯誤日誌。 – justpusher