mohamad mohamad
mohamad mohamad

Reputation: 631

PHP back to search result after click any button or link

I have a php page in this page i show data from mysql database in a table also in the same page i have an HTML form to do some search and the result of this search also appear in the same page.

Each row of this table have an icon delete when i click this icon i delete the information of this row from mysql database.

This my delete code

if(isset($_GET['delete'])){
    $deleteid=secure($_GET['delete'],"num");
    $checkQuery=mysqli_query($conn,"select column from table where column='$deleteid' limit 1")or die(mysqli_error($conn));
    if(mysqli_num_rows($checkQuery)==1){
        dbRowDelete("table","WHERE column='$deleteid'");
        header("location:gm-tasks.php?msg=8");
    }else{
        header("location:gm-tasks.php");
    }
}

An example of my show data and search code:

if(!isset($_POST['submit']) || isset($_POST['clear']) ){
//show all data
}

if(isset($_POST['submit'])) {
//Show search results
}

My question is how can after i delete a row to back to the search result.

I don't want after delete to show all data i want only to show the result of the search without the row i was delete.

I have tried this $_SERVER['http_referrer']; but it didn't solve my problem

Upvotes: 0

Views: 562

Answers (1)

Quentin
Quentin

Reputation: 943630

You have POST and GET backwards.

  • GET should be safe. You should not use GET to delete things. POST can be unsafe. You should use POST to delete things (that or DELETE, which isn't practical with a regular form submission). (This is according to the HTTP specification).
  • GET is designed to GET information. You should use GET when you are searching to show data.
  • GET stores data in the URL, so you can link to it. POST does not. You need to link to the search results to go back to them.

Upvotes: 5

Related Questions