我有一个问题,
当我按下提交按钮时,它应显示在changepassword.php?成功消息中,更改成功但它显示我" HTTP错误404.0 - 未找到"
这是我的代码:
<?php
include 'php_script/init.php';
if (empty($_POST) === false){
$required_fields = array('current_password', 'password', 'password_again');
foreach($_POST as $key=>$value){
if (empty($value) && in_array($key, $required_fields) === true){
$errors[] = 'Trebate ispuniti sva polja';
break 1;
}
}
if (md5($_POST['current_password']) === $user_data['password']){
if (trim($_POST['password']) != trim($_POST['password_again'])){
$errors[] = 'Lozinke se ne poklapaju';
}else if (strlen($_POST['password']) < 6){
$errors[] ='Vaša nova lozinka mora sadržavati barem 6 znakova';
}
} else{
$errors[] = 'Vaša trenutna lozinka je netočna';
}
}
?>
<?php
if (isset($_GET['success']) && empty($_GET['success'])){
echo 'Vaša lozinka je promijenjena';
}else{
if (empty($_POST) === false && empty($errors) === true){
change_password($session_user_id, $_POST['password']);
header('Location: changepassword.php?success');
}else if (empty($errors) === false){
echo output_errors($errors);
}}
?>
<form action="" method="post">
<ul>
<li>Trenutna lozinka:<br><input type="password" name="current_password"/></li>
<li>Nova lozinka:<br><input type="password" name="password"/></li>
<li>Ponoviti lozinku:<br><input type="password" name="password_again"/></li>
<li><input type="submit" value="Promijeni"/></li>
</ul>
</form>
由于
答案 0 :(得分:0)
你的情况不对,
更改此
if (isset($_GET['success']) && empty($_GET['success'])){
到
if (isset($_GET['success']) && ($_GET['success'] != "")){
或
if (isset($_GET['success']) && !empty($_GET['success'])){
答案 1 :(得分:0)
您提交表单,检查所有错误信息,然后您想再次重新加载页面以显示错误,或者&#34;成功更改&#34;消息。
不需要上次重新加载。
改变这个:
<?php
if (isset($_GET['success']) && empty($_GET['success'])){
echo 'Vaša lozinka je promijenjena';
}else{
if (empty($_POST) === false && empty($errors) === true){
change_password($session_user_id, $_POST['password']);
header('Location: changepassword.php?success');
}else if (empty($errors) === false){
echo output_errors($errors);
}}
?>
到
<?php
if ( ! empty($_POST) && empty($errors) ){
// not empty $_POST means we did some validation
// empty $errors, no errors were found while validating
change_password($session_user_id, $_POST['password']);
echo 'Vaša lozinka je promijenjena';
}
if ( ! empty($_POST) && ! empty($errors) ){
// not empty $_POST means we did some validation
// errrors were found let's display them
echo output_errors($errors);
}
?>