标题位置不起作用

时间:2013-02-28 14:47:58

标签: php html mysql

我正在创建一个基本的登录和注册页面,在完成更改密码表单后,我想重定向到changepassword.php?success。如果进入浏览器,重定向页面工作正常,但是在提交表单时,它会重新加载changepassword.php页面而不是?success,并且不会显示php代码块中的所有内容(即表单,列右侧和页脚)。下面是我的changepassword.php代码:

<!DOCTYPE html>
<html>
<?php 
include ("storescripts/init.php");
protect_page();
include ("includes/overall/head.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[] = 'Fields marked with an asterisk are required';
        break 1;
    }
}
if ($_POST['current_password'] === $member_data['mem_password']) {
    if(trim($_POST['password']) !== trim($_POST['password_again'])){
        $errors[] = 'Your new passwords do not match';
    } else if (strlen($_POST['password']) <6) {
        $errors[] = 'Your password must be at least 6 characters';
    }
} else {
    $errors[] = 'Your current password is incorrect';
}
}
?>
<body>
<?php include ("includes/overall/template_header.php");?>
<div id="mainDivShort">
    <h1>Change Password</h1>
    <div id="divBreak"></div>
    <?php include ("includes/overall/column_left.php"); ?>
    <div id="middleContent">
        <?php
        if (isset($_GET['success']) && empty($_GET['success'])) {
echo 'You have been registered successfully';
} else {

    if (empty($_POST) === false && empty($errors) === true) {
        //echo "**********************";
        change_password($session_mem_id, $_POST['password']);
        header('Location: changepassword.php?success');
        exit();
    } else if (empty($errors) === false) {
        echo output_errors($errors);
    }

    ?>
        <form action="" method="post">
            <ul>
                <li>Current Password*: <br> <input type="password"
                    name="current_password">
                </li>
                <li>New Password*: <br> <input type="password" name="password">
                </li>
                <li>Repeat New Password*: <br> <input type="password"
                    name="password_again">
                </li>
                <li><input type="submit" value="Change">
                </li>
            </ul>
        </form>
        <?php }?>
    </div>
    <?php include ("includes/overall/column_right.php"); ?>
</div>
<?php include ("includes/overall/template_footer.php");?>
</body>
</html>

然后你需要查看更改密码功能:

function change_password($mem_id, $password) {
$mem_id = (int)$mem_id;

mysql_query("UPDATE `members` SET `mem_password` = '$password' WHERE `mem_id` = $mem_id");
}

密码在数据库上更新正常,它纯粹不会重定向到成功页面。 提前致谢

2 个答案:

答案 0 :(得分:0)

标题指令必须在内容,任何内容,包含换行符,空格,html等之前出现......否则发送标题为时已晚。只要发送了1位内容,标题就已经消失了。

答案 1 :(得分:-1)

输出任何内容后,您无法输入header('Location: changepassword.php?success');。此外,header重定向应包含绝对路径。