PHP表单session_start():无法发送会话缓存限制器

时间:2014-12-03 11:14:39

标签: php html mysql database

我收到错误消息“:session_start():无法发送会话缓存限制器 - 已发送的标头(输出在/home/page4_insertdata.php:30开始) /home/page4_insertdata.php在第31行“

我检查了空白/空白区域,我找不到任何内容,不确定在30/31行之前输出到浏览器的内容。


PHP


<?php
    // Turn off all error reporting 
    error_reporting(0);
    // Report simple running errors 
    error_reporting(E_ERROR | E_WARNING | E_PARSE);
    // Reporting E_NOTICE can be good too (to report uninitialized 
    // variables or catch variable name misspellings ...) 
    error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    // Report all errors except E_NOTICE 
    // This is the default value set in php.ini 
    error_reporting(E_ALL ^ E_NOTICE);
    // Report all PHP errors (see changelog) 
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    // Report all PHP errors 
    error_reporting(-1);
    // Same as error_reporting(E_ALL); 
    ini_set('error_reporting', E_ALL);
    ?>
<html>
    <head>
        <title>Page Form</title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <div class="container">
            <div class="main">
                <h2>PHP Form</h2><hr/>
                <?php

    session_start();

    if (isset($_POST['state'])) {

        if (!empty($_SESSION['post'])){

            if (empty($_POST['address1'])|| empty($_POST['city'])|| empty($_POST['pin'])|| empty($_POST['state'])){
                //Setting error for page 3
                $_SESSION['error_page3'] = "Mandatory field(s) are missing, Please fill it again";
                header("location: page3_form.php");
                //redirecting to third page
            } else {
                foreach ($_POST as $key => $value) {
                    $_SESSION['post'][$key] = $value;
                }

                //function to extract array
                extract($_SESSION['post']);
                //Storing values in database
                $connection = mysql_connect("localhost","my_user","my_password","my_db");
                $db = mysql_select_db("user_details", $connection);
                $query = mysql_query("insert into detail (name,email,contact,password,religion,nationality,gender,qualification,experience,address1,address2,city,pin,state) values('$name','$email','$contact','$password','$religion','$nationality','$gender','$qualification','$experience','$address1','$address2','$city','$pin','$state')", $connection);

                if ($query) {
                    echo '<p><span id="success">Form Submitted successfully..!!</span></p>';
                } else {
                    echo '<p><span>Form Submission Failed..!!</span></p>';
                }

                //destroying session
                unset($_SESSION['post']);
            }

        } else {
            header("location: page1_form.php");
            //redirecting to first page
        }

    } else {
        header("location: page1_form.php");
        //redirecting to first page
    }

    ?>
            </div>
        </div>
    </body>
</html>

3 个答案:

答案 0 :(得分:1)

始终尝试使用文件顶部的session_start()函数。

<?php
session_start();
// Turn off all error reporting 
error_reporting(0);

并从其他地方删除它,然后它将正常工作。

答案 1 :(得分:0)

在任何输出之前,你必须在文件的开头调用session_start()命令。 您的HTML实际上在session_start()命令之前输出。

http://php.net/manual/fr/function.session-start.php

答案 2 :(得分:0)

在session_start();

之上有一整块HTML

在HTML模式下,所有内容都会立即推送到浏览器。