2013-10-17 54 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

你我的朋友是救世主。像魅力一樣工作,我學到了新東西。 –