I have written a simple application which has login page. After login search insertion buttons are there. I build this simple application and run successfully last month. But now when i am using this now my pages are not redirecting to next page. i double checked my syntax.
i googled for the answer and found ob_start() method. And now my application is running successfully.
when the first time i have used this application i didn’t use ob_start. But why its not working now without the ob_start(); method.
Please explain.
Search function :
$email = $_POST['search'];
$sql = "select * from employee_details where ";
if($email){
$sql .= " email = '$email' ";
}
$rv = mysql_query($sql);
if(mysql_num_rows($rv) == 0){
$errmsg_arr[] = "Employee records are not found.";
$page = "HomePage.php";
$errflag = true;
errors($page,$errmsg_arr, $errflag );
}
while( $row = mysql_fetch_array($rv)){
$var['employee_id'] = $row['employee_id'];
$var['employeename'] = $row['employee_name'];
$var['email'] = $row['email'];
$var['phone'] = $row['phone'];
$var['address1'] = $row['address1'];
$var['state'] = $row['state'];
$var['country'] = $row['country'];
}
addvars($var);
header("location: EmployeeDetails.php");
addvars function:
function addvars($vars) {
session_start();
$_SESSION[] = array();
foreach($vars as $keys => $vals) {
$_SESSION[$keys] = $vals;
}
}
Errors Function:
function errors($page,$errmsg_arr, $errflag){
if($errflag) {
session_start();
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: $page");
exit();
}
}
Most likely because you try to set headers when they’re already sent out. (you can try to adjust output buffering instead of using
ob_startif it bothers you).