PHP Can't get post data

喜夏-厌秋 提交于 2020-01-04 09:13:26

问题


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

回答1:


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.




回答2:


You forget to set name of email:

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


来源:https://stackoverflow.com/questions/42280476/php-cant-get-post-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!