如何在网页上显示表单输入

How to display form inputs on a web page

我目前正在处理我的第一个作业,我不知道如何继续。我需要使用 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 工具将其发布到实时网站的简单方法?我可以购买域名,但不知道如何建立网站。 Link 或回答所有帮助。谢谢!!

$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>