首页 > 解决方案 > 如何在网页上显示表单输入

问题描述

我目前正在处理我的第一个任务,我不知道如何继续。我需要使用 PHP 和 HTML 创建一个表单,允许用户输入他们的姓名作为文本和年龄作为数字。

该表单将调用 PHP 处理页面。PHP 处理页面将为用户创建一个 HTML 页面,该页面将在 h1 标记中显示“Hello xxxxxxx”。在段落标签中,页面将显示“10 年后,您将 xx 岁”。到目前为止,这是我想出的:

<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/html; chartset=iso-8859-1" /

</head>

<body>

 
 <?php
     // echo "<pre>";
     // print_r($_POST);
     // echo "</pre>';
 ?>
 
 <h1> Hello <strong><?php echo "$uname"; ?><strong></h1>
 
 <p> In 10 years, you will be <strong><?php echo "$unumber"; ?></strong> years old. </p>
 
 

 
</body>
</html>

对于我的 PHP 页面。这适用于我的 HTML:

<?php

   $uname = $_POST['username'];
   $unumber = $_POST['number'];
   
?>
<!DOCTYPE html PUBLIC
<html xmlns=
<head>
<meta http-equiv="content-type" content="text/html; chartset=iso-8859-1" />
<title> Lesson 1 </title>
</head>

<body>
   <form action="lesson-1-process.php" method="post" enctype="multipart/form-data" name="userform" target="_self">
       Name: <input name="username" type="text" /><br/>
       Age: <input name="number" type="text" /><br/>
       <input name="submit" type="submit" />
   </form>
   
</body>
</html>

我不知道我这样做是否正确。另一件事,有没有人知道使用 FTP 工具将其上传到实时网站的简单方法?我可以购买一个域名,但我不知道如何建立一个网站。链接或回答所有帮助。谢谢!!

标签: phphtmlftp

解决方案


分配给$uname并且$unumber应该在 PHP 脚本中,而不是在带有表单的页面中。

并且您需要将 10 添加到表单值以获取 10 年的年龄。

<html xmlns="...">
<head>
<meta http-equiv="Content-Type" content="text/html; chartset=iso-8859-1" /
</head>
<body>

 <?php
   $uname = $_POST['username'];
   $unumber = $_POST['number'];
 ?>
 
 <h1> Hello <strong><?php echo "$uname"; ?><strong></h1>
 
 <p> In 10 years, you will be <strong><?php echo $unumber + 10; ?></strong> years old. </p>
 
</body>
</html>

推荐阅读