I am getting the error message ": session_start(): Cannot send session cache limiter - headers already sent (output started at /home/page4_insertdata.php:30) in /home/page4_insertdata.php on line 31"
I have checked for blank/white space and I can't find any, not sure what is outputting to the browser before lines 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>