Echo不打印fname。请让我知道为什么回声不起作用。 Echo不打印fname。
html表单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form action="submit.php" method="post">
<h1>Sign Up</h1>
<fieldset>
<legend>New Users</legend>
<label for="First Name">First Name</label>
<input type="text" name="fname" placeholder="First Name" required>
<label for="Last Name">Last Name</label>
<input type="text" name="lname" placeholder="Last Name" required>
<label for="Username">Username</label>
<input type="text" id="username" placeholder="Username"requiredrequiredrequired>
<br >
<input type="Submit" required name="submit"value="Submit">
</fieldset>
</form>
</body>
</html>
submit.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php $fname = $_post["fname"]; echo $fname; ?>
<?php $lname= $_post["lname"]; ?>
</body>
</html>
答案 0 :(得分:3)
变化
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php $fname = $_post["fname"]; echo $fname; ?>
<?php $lname= $_post["lname"]; ?>
</body>
</html>
到
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php $fname = $_POST["fname"]; echo $fname; ?>
<?php $lname= $_POST["lname"]; ?>
</body>
</html>
我认为这是因为post变量需要大写
(PHP 4 >= 4.1.0, PHP 5)
$_POST -- $HTTP_POST_VARS [deprecated] — HTTP POST variables
答案 1 :(得分:0)
先修复html
你是这样写的吗?
<input type="text" id="username" placeholder="Username"requiredrequiredrequired>
我试一试,它有效。 我创建了echo.php。 测试一下。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
$fname = $_POST["fname"]; echo $fname;
$lname= $_POST["lname"]; echo $lname;
?>
<form action="echo.php" method="post">
<h1>Sign Up</h1>
<fieldset>
<legend>New Users</legend>
<label for="First Name">First Name</label>
<input type="text" name="fname" placeholder="First Name" />
<label for="Last Name">Last Name</label>
<input type="text" name="lname" placeholder="Last Name" />
<label for="Username">Username</label>
<input type="text" id="username" placeholder="Username" />
<br >
<input type="Submit" required name="submit"value="Submit">
</fieldset>
</form>
</body>
</html>
你可以制作更漂亮的代码。
答案 2 :(得分:0)
试试这个 注意:为了方便起见,我将两个页面一起加入并命名为submit.php。你可以分开它
<?php
if(isset($_POST["fname"])){
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php $fname = $_POST["fname"];
echo $fname;
$lname= $_POST["lname"];
echo $lname?>
</body>
</html>
<?php
}
else{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form action="submit.php" method="post">
<h1>Sign Up</h1>
<fieldset>
<legend>New Users</legend>
<label for="First Name">First Name</label>
<input type="text" name="fname" placeholder="First Name" required>
<label for="Last Name">Last Name</label>
<input type="text" name="lname" placeholder="Last Name" required>
<label for="Username">Username</label>
<input type="text" id="username" placeholder="Username"requiredrequiredrequired>
<br >
<input type="Submit" required name="submit"value="Submit">
</fieldset>
</form>
</body>
</html>
<?php }?>