php新手,我只想回显名字,有人能帮我吗!
当我点击提交按钮时,它会重定向到action.php,然后我想要从上一页的表单中回显我的名字。
这是我的代码:
action.php
<?php
echo "Great! Thanks" . $s1 . " for responding to our survey" ;
?>
index.php
<head>
<title>Idiot Box Survey</title>
<meta charset="utf-8">
</head>
<body>
<form action="action.php" method="post">
<label>Firstname : </label>
<input type="text" name="fname"><br><br>
<label>Lastname : </label>
<input type="text" name="lname"><br><br>
<label>Year of birth : </label>
<input type="date" name="ybirth"><br><br>
<label>Year at School : </label>
<input type="date" name="yschool"><br><br>
<label>When will You Wake up : </label>
<input type="time" name="wake"><br><br>
<label>How much time you spend on studying : </label>
<input type="time" name="study"><br><br>
<label>How much time you spend on Video games : </label>
<input type="time" name="vgames"><br><br>
<label>How much time you spend on tv : </label>
<input type="time" name="tv"><br><br>
<label>How much time you spend with family : </label>
<input type="time" name="family"><br><br>
<label>How much time you spend with friends : </label>
<input type="time" name="friends"><br><br>
<label>When will You Sleep : </label>
<input type="number" name="sleep"><br><br>
<button type="submit" name="submit"> Submit Form </button>
</form>
</body>
action.php,但无论哪种方式,您的名字都将在$_POST['fname']
中
<?php echo $_POST['fname']?>
使用输入的名称属性打印其他字段
<?php echo $_POST['lname']?> //for the last name and soo ..
因为我的编辑显然在其他答案中不被接受。不要在$s1中调用不存在的php变量,而是在action.php页面上编写以下内容。
if($_POST["submit"]){
$fname = $_POST["fname"];
echo "Great! Thanks" . $fname . " for responding to our survey" ;
}
这允许表单将提交的数据传递给所需的脚本。当您点击提交按钮时,您将看到您在fname输入字段中输入的值。