I'm trying to allow a user to delete a something they uploaded and then get redirected to the homepage. The delete SQL is working fine, the issue is that I can't get it to run header("Location: index.php")
. I don't know what could be causing this.
This is my code:
public function deletePage ($session_id, $page_id, $url) {
//Database Connection
$db = Database::getInstance();
//Validate page belongs to current user.
if ($this->checkpageOwner($session_id, $page_id)) {
//Delete page
$query = $db->getConnection()->prepare("DELETE FROM pages WHERE page_id = :page_id;
DELETE FROM ratings WHERE page_id = :page_id;
DELETE FROM comments WHERE page_id = :page_id;
DELETE FROM views WHERE page_id = :page_id");
$query->execute(array(
':page_id' => $page_id
));
//Redirect
header("Location: index.php");
} else {
//Set error message
setcookie("sessionPersist", 1);
$_SESSION['message'] = "You don't own this page.";
//Redirect
header("Location: " . $url);
}
}