我有一个允许用户更改密码的表格。 这确定是否存在错误:
if ($userpassword !== $retrievedpassword)
{
$_SESSION['errMsg1'] = "Invalid current password.";
}
elseif ($newuserpassword !== $confirmnewuserpassword){
$_SESSION['errMsg2'] = "The password and confirmation password do not match.";
}
elseif (strlen($message)<6){
$_SESSION['errMsg3'] = "The new password must be at least 6 characters long.";
}
else
{
// update database
}
}
然后,我想使用警报alert-danger向用户显示错误消息:
<div class="form-row">
<div class="col-12">
div class="md-form">
<?php
if (!empty($_SESSION['errMsg1']) or !empty($_SESSION['errMsg2']) or !empty($_SESSION['errMsg3'])){
?>
<div class="alert alert-danger" role="alert">
<?php
if (!empty($_SESSION['errMsg1'])
{
echo $_SESSION['errMsg1'];
unset($_SESSION['errMsg1']);
}
elseif (!empty($_SESSION['errMsg2'])
{
echo $_SESSION['errMsg2'];
unset($_SESSION['errMsg2']);
}
else
{
echo $_SESSION['errMsg3'];
unset($_SESSION['errMsg3']);
}
}
?>
</div>
</div>
</div>
</div>
我对此行有疑问:
“ if(!empty($ _ SESSION ['errMsg1']){”
错误:语法错误:意外标记“ {”。
如何将其更改为显示错误消息的任何组合? 谢谢。