簡體   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