2
如何從下面的代碼中的文本字段獲取輸入?從PHP和HTML中的回顯文本字段獲取輸入?
<?php
echo "<form action='signup.php' method='POST'>";
echo "<input type='text' placeholder='Username' name='username'/>";
echo "<button type='submit' name = 'submit' value='Register' >Sign up</button>";
echo "</form>";
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password,"vaccinations");
$Iusername = $_POST['username'];
if(isset($_POST['submit'])){
$Iusername = $_POST['username'];
echo $Iusername;
echo "whadddup";
}
?>
這是給我的用戶名是一個未定義的索引。我要搶這是呼應
右後'$ conn',你有'$ Iusername = $ _ POST [ '用戶名'];'。而且每次你訪問這個代碼並且不提交表單(當你第一次訪問它時),它會產生這個警告。簡單的解決辦法:刪除這一行,因爲你把它定義中的'如果(isset($ _ POST [ '提交'])){'(無需定義兩次) – Qirel
'$ Iusername = $ _ POST [ '用戶名']; '刪除它,因爲你'如果把它(isset($ _ POST [「提交」])){'條件,並且是足夠 –
[PHP的可能重複:「通知:未定義變量」和「通知:未定義指數」 (http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Qirel