问题
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