php - 如何在网页上显示表单输入
问题描述
我目前正在处理我的第一个任务,我不知道如何继续。我需要使用 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 工具将其上传到实时网站的简单方法?我可以购买一个域名,但我不知道如何建立一个网站。链接或回答所有帮助。谢谢!!
解决方案
分配给$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>
推荐阅读
- html - 响应式嵌套网格布局
- android - 如何通过 kotlin 中的序数值获取枚举成员?
- ruby - 如何将权限标头添加到 grpc ruby 客户端存根?
- asp.net-mvc - 需要将 MVC 站点托管为子站点
- c# - 使用 MVVM 的 Unity 构造函数注入无法按预期工作
- c# - c# xml 嵌套类中缺少元素
- java - Android Studio 无法覆盖未找到的视图布局?
- java - ClassCastException 在使用 ManagedExecutorService 创建的线程中编组对象
- c# - 开发服务器 Asp.net MVC 中的应用程序调用 Error.cshtml
- reactjs - 状态未从 NaN 更新