我的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';
?>
表单正在工作(显示),空错误消息也正常工作 但我在标题中有这些消息。 请问有什么问题和解答?
答案 0 :(得分:2)
你的逻辑是关闭的。首先检查是否按下了提交,然后检查您的输入是否为空。
另外,看起来好像你的整个代码都在同一个文件中,反过来给你那些通知。一旦您的页面加载,它就会抛出这些错误。
<?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存储密码。这是不推荐的,并且已经很老了,不再被认为可以安全地用作密码存储功能。
使用以下其中一项:
crypt()
bcrypt()
scrypt()
password_hash()
功能。其他链接:
关于列长的重要说明:
如果您决定使用password_hash()
或隐藏,请务必注意,如果您当前的密码列的长度低于60,则需要将其更改为(或更高)。手册建议长度为255。
您需要更改列的长度并重新开始使用新哈希才能使其生效。否则,MySQL将无声地失败。
答案 1 :(得分:1)
尝试这样:
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>";
}
}
}