PHP/HTML 表单提交

发布于 2024-10-29 17:44:00 字数 974 浏览 2 评论 0 原文

我有 HTML 和 PHP

    <form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name<form method="post">
    <input name="servername" type="text" /></form>

    <p>Description<form method="post">
    <input name="description" type="text" /></form>

    <p>Server IP<form method="post">
    <input name="ip" type="text" /></form>

    <p>Tags (ex: &quot;pvp, economy, fun&quot;)<form method="post">
    <input name="tags" type="text" /></form>

    <form method="post">
        <input name="submitserver" type="submit" value="submit" /></form>
    </p>

代码 (addaserver.php)

$servername=$_POST['servername'];
$desc=$_POST['description'];
$ip=$_POST['ip'];
$tags=$_POST['tags'];

显然我正在尝试从表单中获取数据...但是,当我单击“提交”时,它只是重新加载表单所在的页面。这可能只是一些简单的错误,但我无法弄清楚出了什么问题 D:

I have the HTML and PHP code

    <form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name<form method="post">
    <input name="servername" type="text" /></form>

    <p>Description<form method="post">
    <input name="description" type="text" /></form>

    <p>Server IP<form method="post">
    <input name="ip" type="text" /></form>

    <p>Tags (ex: "pvp, economy, fun")<form method="post">
    <input name="tags" type="text" /></form>

    <form method="post">
        <input name="submitserver" type="submit" value="submit" /></form>
    </p>

and
(addaserver.php)

$servername=$_POST['servername'];
$desc=$_POST['description'];
$ip=$_POST['ip'];
$tags=$_POST['tags'];

Obviously I'm trying to get the data from the forms...however when I click "submit" it just reloads the page the forms are on. It's probably just some simple error, but I can't figure out what's wrong D:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

过期以后 2024-11-05 17:44:00

您应该只定义一种形式,而不是为每个输入定义一种形式:

<form name="addaserver" method="post" action="addaserver.php">
inputs, inputs, inputs, submit
</form>

You're supposed to define only one form, not one for each input:

<form name="addaserver" method="post" action="addaserver.php">
inputs, inputs, inputs, submit
</form>
耳钉梦 2024-11-05 17:44:00

我看到的第一件事是错误的,即同一个 HTML 中有两个单独的表单标签。

第二个几乎没有用,因为它不向任何目标或操作提供任何数据。我会重组你的 HTML 使其更像这样并尝试一下;

<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></p>

<p>Description<form method="post">
<input name="description" type="text" /></p>

<p>Server IP<form method="post">
<input name="ip" type="text" /></p>

<p>Tags (ex: "pvp, economy, fun")
<input name="tags" type="text" /></p>

<p><input name="submitserver" type="submit" value="submit" /></p>
</form>

另请注意,我删除了所有结束表单标签,因为它们也会引起问题。您只需要在表单主体的最外侧部分有一个结束标记,如代码示例所示。

First thing I see wrong is that you have two separate form tags in the same HTML.

The second one is pretty much useless as it provides no data to any target or action. I would restructure your HTML to be more like this and try it;

<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></p>

<p>Description<form method="post">
<input name="description" type="text" /></p>

<p>Server IP<form method="post">
<input name="ip" type="text" /></p>

<p>Tags (ex: "pvp, economy, fun")
<input name="tags" type="text" /></p>

<p><input name="submitserver" type="submit" value="submit" /></p>
</form>

Also take note of the fact that I got rid of all your closing form tags as they would have caused issues too. You only need one closing tag at the very outside most segment of your form's body as shown in the code sample too.

静谧幽蓝 2024-11-05 17:44:00

您的代码中有太多

标记。

您的代码应以

开头,并以

结尾,但中间应该只有输入字段。

您在第一个

标记中将操作定义为“addaserver.php”,但提交按钮位于不同的 标记之后,因此它不会尊重您设定的初始目标。

You have way too many <form method="post"> tags in your code.

Your code should start with <form method="post"> and end with </form>, but in between there should only be input fields.

You define action to 'addaserver.php' in the first <form> tag, but the submission button is after a different <form> tag so it doesn't respect that initial target you are setting.

她说她爱他 2024-11-05 17:44:00

您似乎将所有输入元素都包含在不同的标签中。表单标签是表单元素的集合,提交表单时将提交其值。如果您没有在表单上指定操作属性,它将(如您所说)重新加载页面。因此,在上面的示例中,如果您删除输入标签周围的所有标签并将它们全部放在同一标签下,您应该会发布您的信息

查看 http://www.w3schools.com/html/html_forms.asphttp://www.tizag.com/phpT/examples/formex.php 了解如何执行此操作的示例。

希望这是有道理的。

You seem to be enclosing all your input element in different tags. a Form tag is a collection of Form elements that will have their values submitted when the form is submitted. And if you do not specify the action attribute on a form it will (as you say) reload the page. So in the above example if you remove all the tags surrounding the input tags and put them all under the same tag you should get your information posted

Look at http://www.w3schools.com/html/html_forms.asp and http://www.tizag.com/phpT/examples/formex.php for examples on how to do this.

Hope that makes sense.

鹿港小镇 2024-11-05 17:44:00

您只需要一个表单标签即可提交整个表单

<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name
<input name="servername" type="text" /></p>

<p>Description
<input name="description" type="text" /></p>

<p>Server IP<form method="post">
<input name="ip" type="text" /></p>

<p>Tags (ex: "pvp, economy, fun")
   <input name="tags" type="text" />

   <input name="submitserver" type="submit" value="submit" /></form>
</p>

You only need one form tag for the whole form to submit

<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name
<input name="servername" type="text" /></p>

<p>Description
<input name="description" type="text" /></p>

<p>Server IP<form method="post">
<input name="ip" type="text" /></p>

<p>Tags (ex: "pvp, economy, fun")
   <input name="tags" type="text" />

   <input name="submitserver" type="submit" value="submit" /></form>
</p>
走过海棠暮 2024-11-05 17:44:00

您在整个表单中嵌套了额外的表单标签。您只需要一个表单标签。所有输入都在其中。

<form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name</p>
    <input name="servername" type="text" />

    <p>Description<</p>
    <input name="description" type="text" />

    <p>Server IP</p>
    <input name="ip" type="text" />

    <p>Tags (ex: "pvp, economy, fun")</p>
    <input name="tags" type="text" />

    <input name="submitserver" type="submit" value="submit" />
</form>

You're nesting extra form tags throughout your form. You only need one form tag. All of the inputs go inside it.

<form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name</p>
    <input name="servername" type="text" />

    <p>Description<</p>
    <input name="description" type="text" />

    <p>Server IP</p>
    <input name="ip" type="text" />

    <p>Tags (ex: "pvp, economy, fun")</p>
    <input name="tags" type="text" />

    <input name="submitserver" type="submit" value="submit" />
</form>
柠檬心 2024-11-05 17:44:00

试试这个:

<form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name: <input name="servername" type="text" /></p>
    <p>Description: <input name="description" type="text" /></p>
    <p>Server IP: <input name="ip" type="text" /></p>
    <p>Tags (ex: "pvp, economy, fun")<input name="tags" type="text" /></p>
    <p><input name="submitserver" type="submit" value="submit" /></p>
</form>

Try this instead:

<form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name: <input name="servername" type="text" /></p>
    <p>Description: <input name="description" type="text" /></p>
    <p>Server IP: <input name="ip" type="text" /></p>
    <p>Tags (ex: "pvp, economy, fun")<input name="tags" type="text" /></p>
    <p><input name="submitserver" type="submit" value="submit" /></p>
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文