gpt4 book ai didi

php - '未定义索引 : submit' happens

转载 作者:行者123 更新时间:2023-11-28 23:16:27 24 4
gpt4 key购买 nike

报错信息是:Notice: Undefined index: submit in G:\wamp64\www\mysql\index2.php on line 2。我在输入 session 中设置了提交。为什么会这样?

<?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>

最佳答案

代替:-

if ($_POST['submit']) {

做:-

if (isset($_POST['submit'])) {

最好直接检查表单值而不是提交检查

if(!empty($_POST['email']) && !empty($_POST['password'])){

注意:- 您的查询针对 SQL 注入(inject) 打开。因此,请阅读 mysqliprepared statements 并使用它们。他们会处理所有事情,例如逃逸和安全漏洞。

关于php - '未定义索引 : submit' happens,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43703044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com