2013-10-17 33 views
-2

我有下面的PHP代码的一些问题:标题位置问题。不能似乎找到了问题的if else语句

require '../core/connection.php'; 
require '../includes/functions.php'; 
if (isset($_SESSION['user_id'])) { 
    if (isset($_POST['current_user_password'])) { 
     $current_user_password = md5($_POST['current_user_password']); 
     if ($current_user_password != $_SESSION['user_password']) { 
      header('Location:../edit_credentials.php?edit=password&error=current_password'); 
     } else { 
      $new_password = $_POST['new_user_password']; 
      $new_password2 = $_POST['new_user_password2']; 
      if ($new_password == '' || ($new_password2 == '') { 
       header('Location:../edit_credentials.php?edit=password&error=new_password_empty'); 
      } 
      if ($new_password != $new_password2) { 
       header('Location:../edit_credentials.php?edit=password&error=new_password_not_equal'); 
      } else { 
       $new_password = md5($new_password); 
       edit_user_password($user_id,$new_password); 
      } 
     } 
    } else { 
     echo 'current_user_password not set'; 
    } 
} else { 
    echo 'Session not set'; 
} 

下面是函数,以及:

function edit_user_password($user_id,$user_password){ 
    global $db; 
    $user_password_data = $db->query(' 
     UPDATE `users` 
     SET `user_password` = "'.$user_password.'" WHERE `user_id` = "'.$user_id.'";'); 
     $_SESSION['user_password'] = $user_password; 
     $db->query($user_password_data); 
     header("Location:../edit_credentials.php?saved=password"); 
} 

一切正常,除了这一部分:

if ($new_password == '' || ($new_password2 == '') { 
       header('Location:../edit_credentials.php?edit=password&error=new_password_empty'); 
      } 

当谈到这部分,密码是空的,如果我用死('测试')切换重定向,它的工作原理,但它不会工作重定向。你有什么机会知道为什么这不起作用?

在此先感谢您的帮助。

+0

*不会工作*不充分的问题说明。告诉我们你的期望和真正发生的事情。 – Oswald

回答

1

,应该在每台header('Location:...');调用后添加一个exit;。 否则,脚本继续运行。

+0

你我的朋友是救世主。像魅力一样工作,我学到了新东西。 –