I am new to php. I am trying to redirect to a error page in php when I get a mysql connection error, but I get an error stating that I cannot modify the header because the output was already sent on line 8 (where I created the connection). Please can you advise on the proper way of doing this?
<?php
$servername = "localhost:3306";
$username = "danny";
$password = "sql1";
$dbname = "testdb";
try{
$conn = new mysqli($servername, $username, $password, $dbname);
}
catch(Exception $e){
header('Location: /connection_error.php');
die();
}
?>
Thanks
Danny