发送表单POST请求到PHP [英] Sending form POST request to PHP

查看:87
本文介绍了发送表单POST请求到PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将几个表单字段作为POST请求发送到我的PHP页面,但无法正常工作.这是我的代码:

I want to send a couple of form fields as a POST request to my PHP page, but I can't get it to work. Here is my code:

PHP login.php

<?php

if(!ISSET($_POST["username"]) && !ISSET($_POST["password"])) {
    include "login.html";
}
else {
    echo "hi";
}

?>

HTML login.html

<form action="login.php" method="post">
    <label for="username">Username</label><input type="text" id="username"/>
    <label for="password">Password</label>Password<input type="password" id="password"/>
    <input type="submit" value="Submit"/>
</form>

有人能发现我的错误吗?

Can anyone spot my mistake?

推荐答案

您的输入没有name. id用于客户端引用,但是(非唯一)name属性用于在提交数据时确定值的键.没有name的表单控件不能成功(即在表单数据中).

Your inputs do not have names. The id is used for client-side referencing, but it is the (non-unique) name attribute that is used to determine the key for a value when the data is submitted. A form control cannot be successful (i.e. in the form data) without a name.

这篇关于发送表单POST请求到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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