简体   繁体   English

单击提交按钮php mysql后重定向到下一页

[英]Redirect to the next page after clicking on submit button php mysql

I would like to redirect to the next page after clicking on the submit page, but I get the following error: 单击提交页面后,我想重定向到下一页,但是出现以下错误:

Warning: Cannot modify header information - headers already sent by (output started at C:\\xampp\\htdocs\\forms\\P_details.php:80) in C:\\xampp\\htdocs\\P_details.php on line 70 警告:无法修改标头信息-第70行的C:\\ xampp \\ htdocs \\ P_details.php中已经发送过的标头(输出从C:\\ xampp \\ htdocs \\ forms \\ P_details.php:80开始)

the following is the php code on P_details.php 以下是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);
        }

?> ?>

Please assist 请协助

请在页面顶部调用ob_start() ,在底部ob_end_flush() ,或者在header()之前不回显页面上的任何内容

That error appears when you've echoed any output to the browser before heading to another page. 当您在转到另一个页面之前已经向浏览器回显了任何输出时,就会出现该错误。

Check your includes and be sure that you are not doing an echo anywhere. 检查您的包含文件,并确保您未在​​任何地方进行回显。

I moved the line include 'forms/P_details.php' below the header statement 我将标题行下面的包括'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';

?> ?>

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

Possible your included files contains any output? 可能您包含的文件包含任何输出?

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

Or 要么

include 'forms/P_details.php';

Any output possible to insert only after header('Location:Address_insert.php'); 任何可能只在header('Location:Address_insert.php');之后插入的输出header('Location:Address_insert.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM