<html>
<body>
<form action="http://localhost/index1.php" method="post">
Type your name: <input type="text" name="name" value="<?php echo $_POST['name'];?>">
<input type="submit" value="Submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想要做的是在用户输入一个值并按下提交按钮后保持在文本框中输入的数据.
当我按下提交按钮时,它在文本框中发出通知,说明名称是一个未定义的索引,我理解为什么.$ _POST ['name']没有值.
我只是想知道是否有办法做到这一点.我是php和HTML的初学者.
<?php
//check whether the variable $_POST['name'] exists
//this condition will be false for the loading
if(isset($_POST['name']){
$name = $_POST['name'];
}
else{
//if the $_POST['name'] is not set
$name = '';
}
?>
<html>
<body>
<form action="http://localhost/index1.php" method="post">
Type your name: <input type="text" name="name" value="<?php echo $name;?>">
<input type="submit" value="Submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)