The code below submits a post and redirects to another page. Post is submitted, rows are effected in database but I am not able to get redirected after submiiting post.
error_reporting('E_ALL ^ E_NOTICE');
if(isset($_POST['submit'])) {
$title=strip_tags($_POST['title']);
$body=($_POST['body']);
$category=$_POST['category'];
if (empty($_POST['category'])) {
$er = "Please select a category from the options";
}
else if($category != "Controversies" && $category != "Entertainment" && $category != "Health" && $category != "Politics" && $category != "Lifestyle" && $category != "Technology" && $category != "Sports" && $category != "Travel"){
$er = "Please select a valid category";
}
else if (strlen($title) < 5) {
$er = "Make sure title is more than 5 characters";
}
else if (strlen($title) > 100 ) {
$er = "Make sure title is not more than 100 characters";
}
else {
$stmt = $db->prepare("INSERT INTO posts (status,userid, title, body,category) VALUES (:status,:userid,:title,:body,:category)");
$stmt->execute(array(':userid'=>$userid,':status'=>active,':title'=>$title,':body'=>$body,':category'=>$category));
if ($stmt->rowCount() > 0) {
header("Location: mains.php");
exit();
}
else {
$er = 'Some error occured please try again!';
}
}
}
If instead ofheader("Location: mains.php");
I use $er = Post success
I see message after submitting post. So what is wrong with header here. Why code isn't redirecting to mains.php