错误消息是:注意:未定义的索引:在第2行的G:\ wamp64 \ www \ mysql \ index2.php中提交。 我在输入会话中设置了提交。为什么会这样?
<?php
if ($_POST['submit']) {
if(!$_POST['email']) $error.="<br>Please enter your email";
else if (!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) $error.="<br>Please enter a valid email address";
if(!$_POST['password']) $error.="<br>Please enter your password";
else {
if(strlen($_POST['password'])<8) $error.="<br>Please enter a password at least 8 characters";
if(!preg_match('`[A-Z]`',$_POST['password'])) $error.="<br>Please enter at least one Big character in your password";
}
if($error) echo "<br>There were errors in your sign up details";
else{
$link=mysqli_connect("localhost","root","","test");
$query="SELECT * FROM users WHERE email=".mysqli_real_escape_string($link,$_POST['email'])."'";
}
}
?>
<form method="post">
<input type="email" name="email" id="email">
<input type="password" name="password" id="password">
<input type="submit" value="Sign In" name="submit" id="submit">
</form>
答案 0 :(得分:1)
而不是: -
if ($_POST['submit']) {
执行: -
if (isset($_POST['submit'])) {
最好是直接检查表单值而不是提交检查
if(!empty($_POST['email']) && !empty($_POST['password'])){
注意: - 您的查询对SQL Injection
开放。请阅读prepared statements
的{{1}}并使用它们。他们会照顾逃避和安全漏洞等所有事情。