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

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 に答える
0

このエラーは、別のページに移動する前にブラウザーに出力をエコーし​​たときに表示されます。

インクルードを確認し、エコーをどこにも行っていないことを確認してください。

于 2013-02-11T11:19:14.360 に答える
0

インクルード '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 に答える