PHP page doesn't automatically reload after deleting a record?

After deleting the entry, I have the submission header to the previous page, but this is not how I could solve it ..

Recording

has already been removed, but it is still displayed on this page after pressing ctrl + f5, when the page is reloaded from the server, at that time the delete effect is shown.

<?php
     include('../config.php');
    $table=$_REQUEST['table'];
    mysql_query("DELETE FROM ".$table." WHERE id=".$id);
    $_SESSION['message']="Deleted Successfully....";

    header('Location: ' . $_SERVER['HTTP_REFERER']);

?>

      

Also, the same thing happens on all pages, adding an editor is added, and all database actions show the effect after pressing Ctrl + F5 ...

+3


source to share


2 answers


You haven't initialized a variable $id

mysql_query("DELETE FROM ".$table." WHERE id=".$id); // Where is $id initialized?

      

You forgot to add

$id = $_REQUEST['id'];

      

If yours is $id

not initialized, definitley will mysql_query

do some request like:



DELETE FROM ".$table." WHERE id=

Which will get you nowhere, and therefore no deletion will happen.

Notes:

1) Don't use mysql _ if they are deprecated and will be removed in future PHP versions.

2) You feed the variable coming from $_REQUEST

straight to your SQL. This variable must be sanitized .

0


source


Try the following:



<script>
window.location.href="<?php echo $_SERVER['HTTP_REFERER']; ?>"; 
</script>

      

-1


source







All Articles