I'm getting the error Warning: "Cannot modify header information - headers already sent by (output started at /admin3/public/new_admin.php:7) in /admin3/includes/functions.php on line 10"
The output it's referring to is the code directly below. I'm not sure what part it's referring to. If the 7 at the end means line 7, then that matches up with the line I open the php code at. I call functions.php (the second part the error refers to) at the absolute top of the main page that this code lives on.
<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/db_connection.php"); ?>
<?php require_once("../includes/functions.php"); ?>
<?php require_once("../includes/validation_functions.php"); ?>
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?>
<?php 
if (isset($_POST['submit'])) {
$required_fields = array("author", "body");
validate_presences($required_fields);
if (empty($errors)) {
    $author = mysql_prep($_POST['author']);
    $body = mysql_prep($_POST['body']); 
    $page_name = ($_POST['page_name']);
    $query  = "INSERT INTO comments (";
    $query .= "  author, body, page_name";
    $query .= ") VALUES (";
    $query .= "  '{$author}', '{$body}', '{$page_name}'";
    $query .= ")";
    $result = mysqli_query($connection, $query);
    if ($result) {
        redirect_to("new_admin.php");
    } else {
            // Failure
            $_SESSION["message"] = "There was an error that prevented the comment from being saved.";
    }
}
} else {
    $author = "";
    $body = "";
}
?>
Here's the functions I use in the above code. The "line 10" code is "redirect_to" function:
    function mysql_prep($string) {
    global $connection;
    $escaped_string = mysqli_real_escape_string($connection, $string);
    return $escaped_string;
}
    function redirect_to($new_location) {
    header("Location: " . $new_location);
    exit;
}
$connection is what I use for my database connection, which I've double checked is working
I'm not sure how to troubleshoot this, I've used this function before in a similar way, so I don't know if there is a silly error or something I'm not noticing. Thanks for any help!!
 
     
    