4

After the record deletion i have send header to previous page but it's not happen how could i solved it..

record is already deleted but it still show in that page after pressing ctrl + f5 when page is reload from server at that time the effect of deletion is show.

<?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 in all the pages happening same thing adter edit add and all the data base action is showing effect after ctrl+f5 press...

Anakbhai Gida
  • 668
  • 3
  • 20

2 Answers2

0

You have not initialised the variable $id

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

Did you forget to add

$id = $_REQUEST['id'];

If your $id is not initialised, definitley, mysql_query will execute some query like:

DELETE FROM ".$table." WHERE id=

Which will not conclude to anything and hence, no delete will occur.

Notes:

1) Do not use mysql_ functions are they are deprecated and will be removed in upcoming PHP versions.

2) You are feeding a variable coming from $_REQUEST directly to your SQL. The variable needs to be sanitized.

Community
  • 1
  • 1
Pupil
  • 23,834
  • 6
  • 44
  • 66
  • If he is using register_globals then $id will be probably initialized. Anakbhai: put a print mysql_query("DELETE FROM ".$table." WHERE id=".$id); in the first line, so you see the query that is sent to the database... – Peter Nov 28 '14 at 09:00
0

Try this:

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