簡體   English   中英

從Xampp獲得錯誤消息注意:未定義的索引[php]

[英]Got error message from Xampp Notice: Undefined index [php]

我從xampp服務器收到一條錯誤消息,說:

Notice: Undefined index: u_name in C:\xampp\htdocs\kownload\path\admin-rgst.php on line 5

Notice: Undefined index: u_pwd in C:\xampp\htdocs\kownload\path\admin-rgst.php on line 6

Notice: Undefined index: u_email in C:\xampp\htdocs\kownload\path\admin-rgst.php on line 7

我的PHP代碼:

<?php
    include 'header.php';
    ?>
    <?php
$u_name = strip_tags($_POST['u_name']);
$u_pwd = md5($_POST['u_pwd']);
$u_email = strip_tags($_POST['u_email']);
if(isset($_POST['rgstdo'])){
    if(!empty($u_name) or !empty($u_pwd) or !empty($u_email)){
        echo "<h1>Error</h1>";
        }
}
?>

我的html:

 <form action="admin-rgst.php" method="post">
    <table>
<tr>
<td><input type="text" name="u_name" placeholder="username"></td>
</tr>
<tr>
<td><input type="password" name="u_pwd" placeholder="pwd"></td>
</tr>
<tr>
<td><input type="email" name="u_email" placeholder="email"></td>
</tr>
<tr><td><input type="submit" name="rgstdo" value="submit"></td></tr>
    </table>
    </form>

再次PHP

<?
    include 'footer.php';
    ?>

表單正在工作(顯示),並且空錯誤消息也正在工作,但是我在標題中有這些消息。 請問是什么問題和解決方法?

你的邏輯不對。 首先檢查是否按下了提交,然后檢查您的輸入是否為空。

另外,看起來您的整個代碼都在同一個文件中,從而給您這些提示。 頁面加載后立即引發這些錯誤。

<?php

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

$u_name = strip_tags($_POST['u_name']);
$u_pwd = md5($_POST['u_pwd']);
$u_email = strip_tags($_POST['u_email']);

if(!empty($u_name) or !empty($u_pwd) or !empty($u_email)){
    $u_name = strip_tags($_POST['u_name']);
    $u_pwd = md5($_POST['u_pwd']);
    $u_email = strip_tags($_POST['u_email']);

        }

if(empty($u_name) or empty($u_pwd) or empty($u_email)){
        echo "<h1>Error</h1>";
    }

else{
   echo "All fields were filled.";
   }
}
?>

密碼

我還注意到您可能正在嘗試用MD5存儲密碼。 不推薦這樣做,因為它已經很老了,不再被認為可以安全地用作密碼存儲功能。

使用以下之一:

其他連結:

有關列長的重要旁注:

如果確實要決定使用password_hash()或crypt,則必須注意,如果當前密碼列的長度小於60,則需要將其更改為該長度(或更大)。 手冊建議長度為255。

您將需要更改列的長度並以新的哈希值重新開始,以使其生效。 否則,MySQL將靜默失敗。

嘗試這樣:

if(isset($_POST["rgstdo"]){
$u_name = strip_tags($_POST['u_name']);
$u_pwd = md5($_POST['u_pwd']);
$u_email = strip_tags($_POST['u_email']);
if(isset($_POST['rgstdo'])){
    if(!empty($u_name) or !empty($u_pwd) or !empty($u_email)){
        echo "<h1>Error</h1>";
        }
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM