0

单击提交页面后,我想重定向到下一页,但出现以下错误:

警告:无法修改标头信息 - 标头已由第 70 行 C:\xampp\htdocs\P_details.php 中的(输出开始于 C:\xampp\htdocs\forms\P_details.php:80)发送

以下是 P_details.php 上的 php 代码

//connect to connect to the database and initialize all functions
include 'scripts/functions/init.php';
include 'html/head.php';
include 'html/page_title.php';
include 'html/top_menu.php';
include 'titles/P_details.php';

//Generate a random Personid
$Personid = rand(1,9999999);
$_SESSION['Personid'] = $Personid;
//Carry over the Jobid to this page
$Jobid = $_SESSION['SESS_MEMBER_JOB'];

if(empty($_POST)=== false)
    {
        $R_fields = array('Title','Surname','Forename','IdentityNumber','Gender','Race','Nationality');
        foreach($_POST as $key=>$value)
        {
            if (empty($value) && in_array($key,$R_fields)=== true)
                {
                    $errors[] = 'fields marked with (*) are required';
                    break 1;
                }
        }

        if(empty($errors)=== true)
            {

                if($_POST['title'] == '-Select-')
                    {
                        $errors[] ='Please select Title';
                    }
                if($_POST['Gender'] == '-Select-')
                    {
                        $errors[] ='Please select Gender';
                    }
                if($_POST['Race'] == '-Select-')
                    {
                        $errors[] ='Please select Race';
                    }
                if($_POST['Nationality'] == '-Select-')
                    {
                        $errors[] ='Please select Nationality';
                    }

            }

    }

    include 'forms/P_details.php';

    if(empty($_POST) === false && empty($errors)=== true)
        {
            //submit personal details
            $personal_details = array(
            'Personid'=>$Personid,
            'Title' => $_POST['title'],
            'Surname'=>$_POST['Surname'],
            'Forename' => $_POST['Forename'],
            'IdentityNumber'=>$_POST['IdentityNumber'],                                             
            'Gender'=>$_POST['Gender'],
            'Race'=>$_POST['Race'],
            'Nationality'=>$_POST['Nationality'],
            'WorkPermitNumber'=>$_POST['WorkPermitNumber'],
            'JobID'=>$Jobid);                       
            personal_details($personal_details);                        
            //redirect
            header('Location:Address_insert.php');
            exit();                                                                                                                             
        }
    else if(empty($errors) === false)
        {
            //output errors if the errors array is not empty
            echo output($errors);
        }

?>

请协助

4

4 回答 4

1

要么ob_start()在页面顶部和ob_end_flush()底部调用,要么在你之前的页面上不回显任何内容header()

于 2013-02-11T11:22:01.737 回答
0

当您在前往另一个页面之前将任何输出回显到浏览器时,就会出现该错误。

检查你的包含,并确保你没有在任何地方做回声。

于 2013-02-11T11:19:14.360 回答
0

我将行 include 'forms/P_details.php' 移到标题语句下方

<?php

//connect to connect to the database and initialize all functions
include 'scripts/functions/init.php';
include 'html/head.php';
include 'html/page_title.php';
include 'html/top_menu.php';
include 'titles/P_details.php';

//Generate a random Personid
$Personid = rand(1,9999999);
$_SESSION['Personid'] = $Personid;
//Carry over the Jobid to this page
$Jobid = $_SESSION['SESS_MEMBER_JOB'];

if(empty($_POST)=== false)
    {
        $R_fields = array('Title','Surname','Forename','IdentityNumber','Gender','Race','Nationality');
        foreach($_POST as $key=>$value)
        {
            if (empty($value) && in_array($key,$R_fields)=== true)
                {
                    $errors[] = 'fields marked with (*) are required';
                    break 1;
                }
        }

        if(empty($errors)=== true)
            {

                if($_POST['title'] == '-Select-')
                    {
                        $errors[] ='Please select Title';
                    }
                if($_POST['Gender'] == '-Select-')
                    {
                        $errors[] ='Please select Gender';
                    }
                if($_POST['Race'] == '-Select-')
                    {
                        $errors[] ='Please select Race';
                    }
                if($_POST['Nationality'] == '-Select-')
                    {
                        $errors[] ='Please select Nationality';
                    }

            }

    }



    if(empty($_POST) === false && empty($errors)=== true)
        {
            //submit personal details
            $personal_details = array(
            'Personid'=>$Personid,
            'Title' => $_POST['title'],
            'Surname'=>$_POST['Surname'],
            'Forename' => $_POST['Forename'],
            'IdentityNumber'=>$_POST['IdentityNumber'],                                             
            'Gender'=>$_POST['Gender'],
            'Race'=>$_POST['Race'],
            'Nationality'=>$_POST['Nationality'],
            'WorkPermitNumber'=>$_POST['WorkPermitNumber'],
            'JobID'=>$Jobid);                       
            personal_details($personal_details);                        
            //redirect
            header('Location: Address_insert.php');
            exit();                                                                                                                             
        }
    else if(empty($errors) === false)
        {
            //output errors if the errors array is not empty
            echo output($errors);
        }

        include 'forms/P_details.php';

?>

于 2013-02-11T12:21:29.653 回答
0

header('Location:Address_insert.php'); 在任何输出之前。

可能您包含的文件包含任何输出?

include 'html/head.php';
include 'html/page_title.php';
include 'html/top_menu.php';
include 'titles/P_details.php';

或者

include 'forms/P_details.php';

任何输出只能在之后插入header('Location:Address_insert.php');

于 2013-02-11T12:42:04.550 回答