2011-02-27 54 views
0

這是我的html表單,在這個下面我包含了我的php文本。html form-php問題

但我沒有得到正確的輸出,我不是沒有問題在哪裏?

我還包括輸出,請建議我什麼shuld我做?

<html> 
<head> 
<title> 
Entering data into text 
</title> 
</head> 
<body> 
<h1> 
Entering data into text 
</h1> 
<form action="text.php" method="post"> 
What is ur name ? 

<input type="text" name="data" /> 


<input type="submit" value="send" /> 
</form> 
</body> 
</html> 

這是我的PHP文字:

<html> 
<head> 
<title> 
Reading data from textfields 
</title> 
</head> 
<body> 
<h1> 
reading data from text field 
</h1> 
Thanks for answering, 
<?php echo $_POST["data"];?> 
</body> 
</html> 

輸出:

reading data from text field 
Thanks for answering, 

問題是,數據發送不包含服務器的響應後 請幫我儘可能快

+1

你能用print'r($ _ REQUEST)'在text.php中打印出來嗎? – amitchd

+0

我是soory,請你多解釋一下 – fariz

+0

我是php新手,請幫助我 – fariz

回答

2

我只能說我自己的經驗,但這個作品在我的服務器。我建議的話,那下面的一個爲真:

  1. 您的服務器沒有設置處理PHP(雖然這讓我感到吃驚),也作爲@gAMBOOKa指出(在評論) ,如果你的服務器沒有設置處理php腳本將不會輸出任何除了PHP腳本的原始文本內容之外的任何東西,字面意思是"<?php echo $_POST["data"];?>"
  2. 您試圖通過文件系統(file:///path/to/file.html)訪問頁面,而不是通過服務器(http://localhost/file.html)訪問頁面。

如果「2」是正確的,請將您的網頁和PHP腳本到服務器的文檔根目錄中的目錄,在* nix這可能是像/var/www/directoryName/,並通過http://localhost/directoryName/dataEntryForm.html訪問該頁面。如果您使用的是Windows,則可以使用IIS訪問C:\inetPub\directoryName\,如上所示,使用http://localhost/directoryName/dataEntryForm.html。順便說一句,請原諒我沒有鏈接到一個頁面運行的演示,只是我不希望冒着暴露我的服務器的風險,大概是易受攻擊的腳本。

+0

如果Web服務器沒有爲php配置,不應該輸出'<?php echo $ _POST [「data」];?>'? – HyderA

+0

@gAMBOOKa:是的,它確實應該,但是我使用'[not] s等待處理php'作爲委婉語,除其他外,「沒有正確設置」。另外,我沒有想到...... **編輯過,**和我的感謝!=) –

+0

@gAMBOOKa:他只會在看到頁面源代碼時纔會看到它,在渲染的頁面中, –

0

你的完整代碼是這樣的,我測試了它,完美地工作。

<html> 
<head> 
<title> 
Entering data into text 
</title> 
</head> 
<body> 
<h1> 
Entering data into text 
</h1> 
<form action="text.php" method="post"> 
What is ur name ? 

<input type="text" name="data" /> 


<input type="submit" value="send" name="btn_save" /> 
</form> 
</body> 
</html> 

text.php

<?php 
if(isset($_POST['btn_save'])) 
{ 


     $data=$_POST['data']; 
} 
?> 

<html> 
<head> 
<title> 
Reading data from textfields 
</title> 
</head> 
<body> 
<h1> 
reading data from text field 
</h1> 
Thanks for answering, 
<?php echo $_POST["data"];?> 
</body> 
</html> 

完美的工作。