So, I am working on my graduation project and I am facing this issue where if I try to change the header to another page using PHP's header() function, I get the problem "Cannot modify header information - headers already sent".
I have tried using output_buffers, checked my code couple of times to search for blanks, checked my PHP code to see if there is any lines regarded as output by server. All of those checks, turned out to be fine. And, yet, the problem is still here. The weird thing is that the line being said is starting the output is the tag. The pictures shows is.
The line where the error message says the issue in in (line 9)
Line 136 where I am setting the header
I have searched all over the place and didn't find a solution nor a post having the same issue where the problem is pointed to start at the tag. Any ideas?
CODE:
<!DOCTYPE html>
<html lang="en">
<?php
//Connect to DB
include("connect-mysql.php");
//Start session
session_start();
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,
shrink-to-fit=no">
<title>Search</title>
The beginning of the PHP file. I did some changes, now it says the output started at line 10 (where tag is)
<h1 style="margin-left: 350px; margin-top: 35px;"> Search Results
</h1>
<?php
//Set search var to empty
$_SESSION['search-for'] = "";
// If the search button was pressed
if(isset($_POST['search'])){
// Arrays containing proffesions and regions in the DB to enable users
search by either one of them
$professions = array("SOME VARIABLES TO COMPARE TO");
$regions = array("SOME VARIABLES TO COMPARE TO");
// Store the search bar input into $term
$term = $DBConnect->real_escape_string($_POST['term']);
// If the user is searching by profession or region
if(in_array(strtolower($term), $professions)){
//SOME CODE HERE
if(isset($_GET['a'])){
$_SESSION['search-for'] = $_GET['a'];
header("sp-portfolio.php");
}
?>
</body>
</html>