2017-05-28 77 views
0

我試圖用w3schools PHP教程中的代碼創建一個簡單的表單,但是我沒有得到預期的結果,我的名字和電子郵件輸入元素的內容回顯。簡單的PHP表單問題

PHP加載的所有HTML完好無損,但沒有來自表單元素的信息。

實施例:

enter image description here

我的結果:

enter image description here

HTML代碼:

<html> 
<body> 

    <form action="welcome.php" method="GET"> 
    Name: <input type="text" name="name"><br> 
    E-mail: <input type="text" name="email"><br> 
    <input type="submit"> 
    </form> 

</body> 
</html> 

PHP:

<html> 
<body> 

Welcome <?php echo $_GET["name"]; ?><br> 
Your email address is: <?php echo $_GET["email"]; ?> 

</body> 
</html> 
+0

你確定你已經安裝了網絡服務器嗎? –

+0

我已經安裝了XAMPP並啓用了Apache。 –

+0

您是否填寫輸入並提交表格?或直接調用鏈接? – AdhershMNair

回答

0

這是這麼簡單:

<?php 
$name = $_GET['name']; 
$email = $_GET['email']; 

if (isset($_GET['submit'])) { 
    echo "Welcome " . $name . "<br>"; 
    echo "Your email is " . $email; 
} 
?> 
<html> 
<body> 
<form> 
    Name: <input type="text" name="name"><br> 
    E-mail: <input type="text" name="email"><br> 
    <input type="submit" name="submit"> 
</form> 
</body> 
</html> 

形式的默認方法是$ _GET和動作是當前php文件,所以它不是強制性的write'em。嘗試這個例子,如果問題仍然沒有解決,我會幫助

+1

'$ _GET'不是一種方法 - 它是[超全球](http://php.net/manual/en/language.variables.superglobals.php)。我不確定他的腳本是否將變量傳遞給它,所以他很可能有服務器設置問題。 – Pyromonk