[英]PHP form won't submit to $_POST
新手警報! 我正在Lynda.com上執行Kevin Skoglund的PHP Essentials課程。 頻道 圖11是說明超全局變量的示例。 他正在使用php 5.6,而我的WAMP已針對php 7.0.1進行了設置。 我無法將這種簡單的表單發布到超全局變量,我也不知道為什么。
<?php
if(isset($_POST['submit'])){
$username = $_POST["username"];
$password = $_POST["password"];
$message = "Logging in {$username}";
} else{
$message= "The form was not submitted";
}
;?>
<html lang="en">
<head>
<title>Hello World</title>
</head>
<body>
<?php echo $message;?>
<form method="post" action="">
<label for="username">Username: </label>
<input type="text" name="username" id="username" value=""/>
<br />
<label for="password">Password:</label>
<input type="password" name="password" id="password" value=""/> <br />
<br/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
無論在兩個字段中鍵入什么,輸出始終為null。 它從本地主機目錄運行,WAMP已啟動。 什么會導致這種簡單的錯誤?
首先,感謝所有試圖幫助我的人。 這不是代碼,但最終錯誤似乎起源於PHPstorm。 通過啟動IDE運行php文件時,似乎在本地主機地址中添加了一個端口號。 http://localhost:63342/www/Helloworld.php?_ijt=6jrieg9npqffa11j0l2k3bv05h
這會導致在運行表單時丟失帖子值,結果超全局變量會變空。
當我直接從WAMP菜單啟動localhost並鍵入文件的URL時,例如http://localhost/Helloworld.php
,那么代碼將按預期運行。 我仍然必須弄清楚如何獲取PHPstorm才能將php文件運行到正確的localhost實例中,但是目前有一種解決方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.