PHP无法获取发布数据 [英] PHP Can't get post data

查看:120
本文介绍了PHP无法获取发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的index.php包含...

 < form class =form-signinaction =submit。 phpmethod =post> 
< input class =form-controltype =textid =namename =namerequired =placeholder =Nameautofocus =>
< input class =form-controltype =textid =institutionname =institutionrequired =0placeholder =Institutionautofocus =>
< input class =form-controltype =emailid =emailplaceholder =Email Addressautofocus =/>

但是当我使用...提交表单时...

  $ name = $ _POST ['name']; 
$院校= $ _POST ['院校'];
$ email = $ _POST ['email'];
$ query =INSERT INTO参与者(名称,机构,id)VALUES('。$ name。','。。$ institution。','。。$ email。');

我得到错误...

 注意:未定义的索引:第6行的C:\ Development \XAMPP\htdocs\reg\submit.php中的电子邮件

p>

b
$ b

 < input class =form-controltype =emailname =emailid =emailplaceholder =Email Address autofocus =/> 

当您使用post方法通过表单提交数据时,PHP会将键值对分配给 $ _ POST 全局变量使用表单输入的名称值作为键。



因为您没有为电子邮件输入设置的名称,您的错误告诉您全局 $ _ POST 变量没有(未定义的)密钥(索引)。


My index.php contains...

<form class="form-signin" action="submit.php" method="post">
        <input class="form-control" type="text" id="name" name="name" required="" placeholder="Name" autofocus="">
        <input class="form-control" type="text" id="institution" name="institution" required="0" placeholder="Institution" autofocus="">
        <input class="form-control"type="email" id="email" placeholder="Email Address" autofocus="" />

But when I submit the form using...

$name = $_POST['name'];
$institution = $_POST['institution'];
$email = $_POST['email'];
$query = "INSERT INTO participants (name,institution,id) VALUES ('".$name."','".$institution."','".$email."')";

I get the error...

Notice: Undefined index: email in C:\Development\XAMPP\htdocs\reg\submit.php on line 6

解决方案

You don't have a name field for your email input, please add it:

 <input class="form-control" type="email" name="email" id="email" placeholder="Email Address" autofocus="" />

When you submit data via a form using the post method, PHP assigns key-value pairs to the $_POST global variable using the name value of your form inputs as the keys.

As you didn't have the name set for the email input, your error tells you that there is no (undefined) key (index) of email for the global $_POST variable.

这篇关于PHP无法获取发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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