繁体   English   中英

注意:未定义索引:注册(尝试注册表单时出错?)

[英]Notice: Undefined index: register (error trying to make registration form?)

注意:未定义的索引:在第12行注册。

这是一些旧的网站代码,我正在修复 - 我是一个菜鸟。

最初我使用的是isset() ,但是被迫使用null!==

if (isset($_SESSION['id'])) {    
    echo "<fieldset><legend><b>Error!</b></legend>";
    echo "You are already logged in, therefore you can not register a new account!";
    echo "</fieldset>";
} else {
    if (null !== (!$_POST['register'])) {
        echo "<fieldset><legend><b>Registration</b></legend><br />";
        echo "Fill out all of these fields below in order to create a new account. This account will be used to enter, so you are advised not to share the information with anyone at all!<br /><br />";
        echo "<form method=\"POST\">";

我希望得到一份工作登记表,但是得到这个。 在类似的场景中,我在其他文件中也得到了相同的未定义索引错误。

更换

if (null !== (!$_POST['register']))

if (isset($_POST['register']) && $_POST['register'] != '') // to check not empty

或if(isset($ _ POST ['register']))

检查isset()将检查索引是否已定义。 如果需要检查索引中是否存在任何值,请检查$_POST['register'] != ''

在使用此类方案时,最好检查索引是否存在以及索引中的值是否已定义。 这将节省很多麻烦。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM