So I'm busy on this system to change your password, when the password is changed, a green box appears with the message 'Your password has been changed.'
When there's an error, a red box appears with the error, for example: "Your current password is incorrect", or "Your new password and the verification password aren't the same.".
So when there's a post request, I count the errors, if there's more then 0, return the errors like this:
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();
}
}
Thats the function I use to change passwords. The following is how I 'echo' the errors:
<?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
And still, even tho I only echo the errors, or the success message, if there's more then 1, I get these errors:
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
In the second code block, I numbered the lines so you can see which lines throw the errors.
When doing a var_dump, I get the following output:
array(2) { [0]=> array(0) { } [1]=> string(41) "Whoops, je huidige wachtwoord klopt niet!" }
Also, what I find really weird is that it shows the red error box twice, and even tho there isn't any success message, it also shows the green box...
I hope that this'll be considered a complete question and someone can help me solve this problem. Thanks.