所以我很忙这个系统来改变你的密码,当密码被改变时,一个绿色的方框出现,并显示'你的密码已被改变'。注意:使用Foreach时数组到字符串的转换
出现错误时,出现一个红色框,显示错误信息,例如: “您当前的密码不正确”或“您的新密码与验证密码不一致”。
所以,当有一个post请求,我count
错误,如果有更多的则0,返回的错误是这样的:
public function nieuwpw($username, $currentpass, $newpass, $newpassconf)
{
$this->errors[] = array();
$this->succes[] = array();
$query = $this->db->conn->prepare('SELECT pass FROM ht_users WHERE naam = ?');
$query->bind_param('s', $username);
$query->execute();
$query->bind_result($dbpass);
$query->store_result();
while ($query->fetch()) {
if (password_verify($currentpass, $dbpass))
{
if ($newpass === $newpassconf)
{
$newpasshash = password_hash($newpass, PASSWORD_DEFAULT);
$stmt = $this->db->conn->prepare('UPDATE ht_users SET pass = ? WHERE naam = ?');
$stmt->bind_param('ss', $newpasshash, $username);
$stmt->execute();
$stmt->close();
}
else
{
$this->errors[] = 'Whoops, je 2 nieuwe wachtwoorden zijn niet gelijk.';
}
}
else
{
$this->errors[] = 'Whoops, je huidige wachtwoord klopt niet!';
}
}
if (count($this->errors) > 0)
{
return $this->errors;
}
$this->succes[] = 'Je wachtwoord is met success gewijzigd!';
return $this->succes;
$query->close();
}
}
,这是我用它来修改密码的功能。以下是我如何“回响”的错误:
<?php //24
//25
if(isset($users->succes))//26
{//27
if (count($users->succes) > 0) //28
{//29
foreach ($users->succes as $succes) {//30
$content = '<div id="message_succes" style="background-color:#00B200; width:100%; height:30px;"><p style="color:#fff; font-family:Ubuntu; padding:5px;">' . $succes. '</p></div>';//31
echo $content;//32
//33
} //34
}//35
}//36
if(isset($users->errors))//37
{//38
if (count($users->errors) > 0) //39
{//40
foreach ($users->errors as $errors) {//41
$content = '<div id="message_succes" style="background-color:#ff0033; width:100%; height:30px;"><p style="color:#fff; font-family:Ubuntu; padding:5px;">' . $errors. '</p></div>';//42
echo $content;//43
//44
} //45
}//46
}//47
//48
?> //49
而且还在,甚至尽管我只能随声附和错误或成功的消息,如果有更多的则1,我得到这些错误:
Notice: Array to string conversion in C:\xampp\htdocs\pages\page16.php on line 31
Notice: Array to string conversion in C:\xampp\htdocs\pages\page16.php on line 42
在第二个代码块中,我对行进行了编号,以便您可以看到哪些行会抛出错误。
当做var_dump
,我得到下面的输出:
array(2) { [0]=> array(0) { } [1]=> string(41) "Whoops, je huidige wachtwoord klopt niet!" }
而且,我觉得很奇怪的是,它显示红色的错误框两次,连寿没有任何成功消息,它也显示了绿色框...
我希望这将被视为一个完整的问题,有人可以帮助我解决这个问题。谢谢。