i am trying to create a new subject and redirecting the page to the home page after the subject is created which is(content.php).
The code succesfully created the object but the page redirecting that i try to make is failed and my browser came out with this error message :
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\newcompany\create_subjects.php:15) in C:\xampp\htdocs\newcompany\create_subjects.php on line 29
and i could not figure out whats wrong here,this is the code from the page of create_subject.php :
<?php
$connection = mysql_connect("localhost","root","mypassword");
if (!$connection) {
die ("database failed to connect " . mysql_error());
}
$db_select = mysql_select_db("newcompany");
if (!$db_select) {
die ("database failed to connect " . mysql_error());
}
?>
<?php
$menu_name = $_POST['menu_name'];
$position = $_POST['position'];
$visible = $_POST['visible'];
?>
<?php
$query = "INSERT INTO subjects (
menu_name, position, visible
) VALUES (
'{$menu_name}', {$position}, {$visible}
)";
$result = mysql_query($query, $connection);
if ($result) {
// Success!
header("Location: content.php");
exit;
} else {
// Display error message.
echo "<p>Subject creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php
mysql_close($connection);
?>
could somebody help me please?
Thank You :)