Brendon Wells Brendon Wells - 1 year ago 111
PHP Question

php wont redirect after form submission

I am trying to get my page to redirect after deleting a record from the database but it wont redirect. It is echoing out text and also deleting the record but it just reloads me on the same page with a form that no longer has information in it.

Here is the button im using

echo '<form>';
echo '<br /><br /><input style="cursor:pointer" class="button" type="submit" value="Delete Event" name="delete" id="delete" />';
echo '</form>';

Here is the PHP im using to delete the row from the DB

if (isset($_POST['delete'])){
$mysqli->query('DELETE FROM information WHERE id = '.intval($_GET['id']));
header('Location: index.php');

I have no idea whats wrong with it.

Answer Source

The header doesn't work, probably because there's already another one. I suggest you to use a little part of Javascript:

if (isset($_POST['delete'])){ $mysqli->query('DELETE FROM information WHERE id = '.intval($_GET['id'])); echo "<script type='text/javascript'>window.location.href = 'index.php'</script>"; }