2015-09-05 11 views
0

我想要製作一個html或php頁面(對於某些自己的學習過程),它可以輸入3個選擇,然後在下一頁顯示結果。從一個html頁面的mysql開始結束日期和下拉菜單

1輸入開始日期 2-輸入結束日期 3-展會服務在下拉菜單中通過MySQL查詢名稱從表中

到目前爲止,我已經設法開始和結束獲得服務名稱表和下拉菜單,它成功地查詢服務表並顯示名稱,但問題是,當我點擊提交我可以看到開始和結束日期的結果,但我無法看到如何在發佈中添加服務選擇。 這是我的代碼。

<!DOCTYPE html> 
<html> 
    <head> 
     <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
     <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
     <script> 
      $(document).ready(function() { 
       $("#start_datepicker").datepicker(); 
       $("#end_datepicker").datepicker(); 
      }); 
     </script> 
    </head> 
    <body style="font-size:62.5%;"> 
     <form action="test.php" method="post"> 
      Start Date: <input type="text" name="startdate" id="start_datepicker"> <br /> 
      End Date: <input type="text" name="enddate" id="end_datepicker"><br /> 
      <select name="srvname"> 
      <?php 
       $conn = new mysqli('localhost', 'root', 'SQLPASS', 'radius') 
       or die ('Cannot connect to db'); 

       $result = $conn->query("select srvname name from rm_services"); 

       while ($row = $result->fetch_assoc()) { 
        echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>"; 
       } 
      ?> 
      </select> 
      <input type="submit" value="Submit:"> 
     </form> 
    </body> 
</html> 

,這是test.php的這將每個表單操作顯示日期

<?php 
$STARTDATE = $_POST['startdate']; 
$ENDDATE = $_POST['enddate']; 
$SRVNAME = $_POST['srvname']; //gets the value -> $row["id"] 
echo "<h2>You have entered the following information:</h2>"; 
echo "<pre>$STARTDATE</pre> "; 
echo "<pre>$ENDDATE</pre>"; 
echo "<pre>$SRVNAME</pre>"; 
?> 
+0

你有一些HTML錯誤。看看'

'和''元素及其關閉。你也只是選擇'srvname'而不是'id'或'name'。 – chris85

+0

感謝您的指點,現在我設法更正了代碼,現在三個輸入框顯示一個提交按鈕,但它只提交開始日期到test.php頁面,它不顯示或提交SERVICES名稱到test.php –

+0

你可以更新到你現在有什麼? – chris85

回答

3

這應該工作,併爲未來:如果你張貼在計算器的東西,請發表格式化代碼,它的方式更容易編輯,尤其是閱讀它...

您的index.php或任何...

<!DOCTYPE html> 
<html> 
    <head> 
     <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
     <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
     <script> 
      $(document).ready(function() { 
       $("#start_datepicker").datepicker(); 
       $("#end_datepicker").datepicker(); 
      }); 
     </script> 
    </head> 
    <body style="font-size:62.5%;"> 
     <form action="test.php" method="post"> 
      Start Date: <input type="text" name="startdate" id="start_datepicker"> <br /> 
      End Date: <input type="text" name="enddate" id="end_datepicker"><br /> 
      <select name="srvname"> 
      <?php 
       $conn = new mysqli('localhost', 'root', 'SQLPASS', 'radius') 
       or die ('Cannot connect to db'); 

       $result = $conn->query("select id, name from rm_services"); 

       while ($row = $result->fetch_assoc()) { 
        echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>"; 
       } 
      ?> 
      </select> 
      <input type="submit" value="Submit:"> 
     </form> 
    </body> 
</html> 

你test.php的

<?php 
$STARTDATE = $_POST['startdate']; 
$ENDDATE = $_POST['enddate']; 
$SRVNAME = $_POST['srvname']; //gets the value -> $row["id"] 
echo "<h2>You have entered the following information:</h2>"; 
echo "<pre>$STARTDATE</pre> "; 
echo "<pre>$ENDDATE</pre>"; 
echo "<pre>$SRVNAME</pre>"; 
?> 

我沒有測試它,但實際上它應該工作...

+0

markus 仍然我可以看到開始結束日期,但服務名稱不顯示在test.php結果 –

+0

http://www3.kloiberm.com/so/ - >這一個作品完美...與上面的書面代碼,我已經改變了唯一的事情是數據庫,當然還有查詢.... – Markus

+0

以及服務名稱出現,但是當我提交選擇,然後下一頁負責顯示結果,即只顯示日期的test.php頁面,結果中沒有服務出現。 –

相關問題