简体   繁体   English

以HTML格式提交的数据不显示

[英]Submitted data in HTML form does not display

Can someone tell my why the data I submit in my HTML form does not display? 有人可以告诉我为什么我在HTML表单中提交的数据不显示吗? I am using HTML and PHP. 我正在使用HTML和PHP。 BTW My server is running (APACHE) BTW我的服务器正在运行(APACHE)

<!DOCTYPE HTML>
<html>

<head>
<title>My PHP Project</title>
</head>

<body>

<form action="form.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>

</html>

 //PHP code:
<!DOCTYPE HTML>
<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

You don't need to use body and html tag twice in the same page. 您无需在同一页面中两次使用body和html标签。 On page referesh data won't show because it will on show once form submit so use isset() and try following 在页面上,refesh数据不会显示,因为一旦表单提交,它将显示在屏幕上,因此请使用isset()并尝试执行以下操作

<!DOCTYPE HTML>
<html>

<head>
<title>My PHP Project</title>
</head>

<body>

<form action="form.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" name="submit" value="submit" />
</form>

<?php if(isset($_POST["submit"])){ ?>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
<?php }?>

</body>
</html>

Also you need to make sure that this file name is form.php because action attribute is targeting form.php file 另外,您还需要确保此文件名为form.php因为action属性是针对form.php文件的

You must have two seperate files one is the index.html view and form.php 您必须有两个单独的文件,一个是index.html视图和form.php

In your index file 在您的索引文件中

<!DOCTYPE HTML>
<html>

<head>
<title>My PHP Project</title>
</head>

<body>

<form action="form.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>

</html>

Then in your second file form.php 然后在第二个文件form.php中

 //PHP code:
<!DOCTYPE HTML>
<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM