Reputation: 65
In my website i'm trying to redirect to another page when something is deleted.
In my case I created events and each event got his own page (fe: event.php?event_id=20
). When I am on the eventpage I can delete the event. But if i redirect to another page with the action tag it isn't deleting the event. When I stay on the page it delete the event but it stays on the eventpage.
I tried to use header("location:..."
) to redirect after the query is done but it isn't doing anything. What I'm I doing wrong?
include_once("classes/Event.class.php");
$event = new Event();
if (isset($_POST["btnDeleteEvent"])){
try{
$event_id = $_GET['event_id'];
$event->DeleteEvent($event_id);
}
catch(Exception $e) {
$feedback = $e->getMessage();
}
}
<form class='event_center' class='form-horizontal' action='<?php echo "event.php" . "?event_id=" .$event_id; ?>' method='post'> <img src="images/trash_white.png"/>
<button type='submit' name='btnDeleteEvent' >Delete</button></form>
(here i am executing the query on the page I am but it has to go to events.php
)
function:
public function DeleteEvent($event_id){
$db = new Db();
$select = "DELETE from tblevents WHERE event_id = " . $event_id . "";
$result = $db->conn->query($select);
return $result;
header("Location: events.php");
}
Upvotes: 0
Views: 189
Reputation: 4565
Put the
header("Location: events.php");
before
return $result;
the function terminates at line
return $result;
so it can't reach to the header
statement
Try this :
public function DeleteEvent($event_id){
$db = new Db();
$select = "DELETE from tblevents WHERE event_id = " . $event_id . "";
$result = $db->conn->query($select);
header("Location: events.php");
}
Upvotes: 1