使用 xampp 链接 HTML 表单 [英] Linking HTML form with xampp

查看:41
本文介绍了使用 xampp 链接 HTML 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的 HTML 表单,其中包含两个输入部分,名称和年龄,我想将表单与 xampp 服务器连接.我已经在我的电脑上安装了 xampp.任何人都可以帮助我完成将表单与 xampp 链接的过程.

I have created a simple HTML form with two input sections, Name and age, I want to connect the form with xampp server. I have installed xampp on my PC. Can anyone help me with the procedure for linking the form with the xampp.

表单为 .html 格式.

The form is in .html format.

推荐答案

如果要提取姓名和年龄,则需要在 XAMPP服务器"上使用 PHP.在 XAMP htdocs 文件夹中创建两个文件 index.htmlwelcome.php.

If you want to extract the name and the age, you need to use PHP on your XAMPP 'server'. Create two files index.html and welcome.php in your XAMP htdocs folder.

你的 index.html 文件应该有(参考你问题中的字段名):

Your index.html file should have (Reffering to the fieldnames from your question):

<form action="welcome.php" method="post">
    Name: <input type="text" name="name"><br>
    Age: <input type="text" name="age"><br>
    <button name="submit">Submit</button>
</form>

'action' 会告诉表单你应该发帖到哪里.所以在这个例子中,我们将把数据发布到 welcome.php.

The 'action' will tell that form where you should post to. So in this example we going to post the data to welcome.php.

在您的服务器上,您想知道发布了哪些数据,因此我们需要像这样提取 POST 数据,将下面的代码放在 welcome.php

On your server you want to know what data was posted so we need to extract the POST data like this, place the code below in welcome.php

<?php
// Check if the user hit the submit button
if(isset($_POST["submit"]))
{
    echo "Your name is {$_POST["name"]} and you are {$_POST["age"]} years old.";
}else{
    echo "We don't know your name, please enter your name. <a href='index.html'>Go back</a>";
}
?>

这只是基本的.我希望这能帮助您理解表格.

This is just the basic. I hope this will help you understanding the form.

小示范:

这篇关于使用 xampp 链接 HTML 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆