2013-04-03 24 views
-1

我想開發一個包含兩個窗體的網頁,當頁面加載時只顯示第一個窗體並填充後,第二個窗體根據用戶的需求顯示,兩個窗體的值將被存儲在數據庫的兩個不同的表中我不知道這背後的邏輯是什麼。 PLZ給我建議的解決方案和示例link.thankyou 之前,這是我的代碼只是爲了顯示一種形式,但第二個有相同的圖案如何顯示和隱藏網頁上的表格?我可以做到這一點與PHP?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<?php 
if (!empty($_POST['det_loc'])) { 
    //do something here; 
    mysql_connect("localhost","root");//database connection 
mysql_select_db("admin"); 

//inserting data into DET_LOCATION Table 
$locID=$_POST["LocID"]; 
$latitude=$_POST["Latitude"]; 
$longitude=$_POST["Longitude"]; 
$store = "INSERT INTO det_location(LocID,Latitude,Longitude) VALUES('$locID','$latitude','$longitude')"; 
//declare in the order variable 
$result = mysql_query($store); //order executes 
if($result) 
{ 
    echo "<br>Input data is succeed"; 

} else{ 
    echo "<br>Input data is fail"; 
} 
} 

if (!empty($_POST['more_loc'])) { 
    //do something here; 
    mysql_connect("localhost","root");//database connection 
    mysql_select_db("admin"); 

//inserting data into DET_LOCATION Table 
$latitude=$_POST["Latitude"]; 
$longitude=$_POST["Longitude"]; 
$store = "INSERT INTO det_location(Latitude,Longitude) VALUES('$latitude','$longitude')"; 
//declare in the order variable 
$result = mysql_query($store); //order executes 
if($result) 
{ 
    echo "<br>All data is Entered"; 

} else{ 
    echo "<br>Input data is fail"; 
} 
} 
?> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Input Detail Location</title> 
</head> 

<body> 
<table border="1"> 
    <tr> 
    <td align="center">Det_Location</td> 
    </tr> 
    <tr> 
    <td> 
     <table> 
     <form method="post" action="det_loc"> 
    <tr> 
      <td>locID</td> 
      <td><input type="Integer" name ="LocID" size="20"> 
      </td> 
     </tr> 
    <tr> 
      <td>Latitude</td> 
      <td><input type="Float" name ="Latitude" size="20"> 
      </td> 
     </tr> 
       <tr> 
      <td>Longitude</td> 
      <td><input type="Float" name="Longitude" size="20"> 
      </td> 
     </tr> 
      </form> 
     </table> 

    </td> 
    </tr> 
    <tr> 
    <td> 
<input type="submit" name="det_loc" value="Add more" /> 
</td> 
    </tr> 
    </table> 

    <table border="1"> 
    <tr> 
    <td align="center">More Locations</td> 
    </tr> 
    <tr> 
    <td> 

    <table> 
     <form method="post" action=""> 
    <tr> 
      <td>Latitude</td> 
      <td><input type="Float" name ="Latitude" size="20"> 
      </td> 
     </tr> 
       <tr> 
      <td>Longitude</td> 
      <td><input type="Float" name="Longitude" size="20"> 
      </td> 
     </tr> 
     <tr> 
      <td>Latitude</td> 
      <td><input type="Float" name ="Latitude" size="20"> 
      </td> 
     </tr> 
       <tr> 
      <td>Longitude</td> 
      <td><input type="Float" name="Longitude" size="20"> 
      </td> 
     </tr> 
      </form> 
     </table> 

     </td> 
    </tr> 
    <tr> 
    <td> 
    <input type="submit" name="more_loc" value="Send Data" /> 
    </td> 
     </tr> 
</table> 
</td> 
    </tr> 
    </table> 

</body> 
  • ,但在同一個頁面上同時顯示錶和犯規發送數據到mysql數據庫。

+2

您有一個SQL注入漏洞。 – SLaks 2013-04-03 19:42:11

+0

php不能「隱藏」任何東西,除非它不是首先輸出表單。你有PHP輸出一些CSS,一旦它在客戶端上呈現就可以隱藏表單。樣式指令或內聯'... style =「display:none」'。 – 2013-04-03 19:42:24

+0

[請不要在新代碼中使用'mysql_ *'函數](http://stackoverflow.com/q/12859942/1190388)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到紅色框?改爲了解準備好的語句,然後使用[tag:PDO]或[tag:MySQLi]。 – hjpotter92 2013-04-03 19:43:00

回答

3

這取決於當你想的形式被隱藏。如果你想用PHP隱藏它們,應該在你發送表單給用戶之前完成。否則你會需要JavaScript,或者有多個請求發送到你的服務器。

你試圖達到的效果就像「用槍射擊子彈,並希望當它一半的時候,你把槍指向下面,子彈也會下降。」不會發生。它不能做到。如果您想在其中發生更改,您需要客戶端上的某些東西。

+0

+1爲半空子彈明喻,如果沒有別的;我可能不得不「借」那一個:) – IMSoP 2013-04-03 19:50:51

+0

IMSop肯定:)Mr.Touch,我想顯示第一個表單,當用戶填寫它時,如果他/她想添加更多的字段,所以他/她點擊一個按鈕「添加更多」,它顯示了上述形式的一些字段,在這裏用戶只是管理員。希望你能理解我的問題。 – 2013-04-03 21:12:38

+0

你的意思與gmail讓你上傳1個附件類似,你可以點擊一個鏈接,加載更多的元素,這將允許你添加更多的附件,但在這種情況下,一些輸入?如果是這樣,你是否熟悉JavaScript,更好,jQuery? – Touch 2013-04-03 22:22:35

相關問題