I am getting the following error when i want to add an article with admin page for content management:
"Warning: Cannot modify header information - headers already sent by (output started at cms/includes/connection.php:12) in cms/admin/add.php on line 23"
Could you please help me with this one ? I know that this is a frequent question here but i dont have enough experience to solve this by myself. Thank you.
This is my file connection.php
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
try{
    $pdo = new PDO('mysql:host=localhost; dbname=cms', 'root','root');
} catch (PDOException $e) {
    exit('Database error.');
}
?>
This is my add.php file
<?php
session_start();
include_once ('../includes/connection.php');
if (isset($_SESSION['logged_in'])) {
    if(isset($_POST['title'],$_POST['content'])) {
        $title = $_POST['title'];
        $content = $_POST['content'];
        if(empty($title) or empty($content)) {
            $error = 'All fields are required!';
        } else {
            $query = $pdo->prepare('INSERT INTO articles (article_title, article _content, article_timestamp) VALUES (?,?,?)');
            $query->bindValue(1,$title);
            $query->bindValue(2,$content);
            $query->bindValue(3,time());
            $query->execute();
            header('Location: index.php');
        }
    }
      ?>
 <html lang="en">
 <head>
     <title>My Fitness Lifestyle</title>
     <link rel="stylesheet" type="text/css" href="../assets/style.css">
 </head>
 <body>
 <div class="container">
     <a href="index.php" id="logo">CMS</a>
     <br />
     <h4>Add Article</h4>
     <?php if (isset($error))  { ?>
     <small style="color:#900010;"><?php echo $error; ?>
         <br /><br />
         <?php } ?>
     <form action="add.php" method="post" autocomplete="off">
         <input type="text" name="title" placeholder="Title" /><br> <br />
         <textarea rows="15" cols="50" placeholder="Content" name="content"></textarea><br /><br />
        <input type="submit" value="Add Article" />
     </form>
 </div>
 </body>
 </html>
    <?php
}   else {
    header('Location: index.php');
}
?>
 
     
     
    