Vikas Vishwakarma
Vikas Vishwakarma

Reputation: 95

staying in same page using location header in php

I have table which are going in different pages and all row have one attribute which is button and button is used for deleting row from table and when button function performed , it is going in header action , but when it is performed in second page after completing action header is sending it in first page , i want it should stay in same page. How can i do this?

Here is some code

<?php
if(isset($_GET['index_edit_id']))
{
    $delete_id=$_GET['index_edit_id'];
    $sql = "DELETE FROM update_table WHERE  id='$delete_id';UPDATE files SET show_status=null  WHERE id='$delete_id';DELETE FROM callcase WHERE id='$delete_id';DELETE FROM lettercase WHERE id='$delete_id'";
    $run=mysqli_multi_query($con,$sql);
    header("location:index.php");
}
?>

I want to send location with pagination number and if it is with search key then it should also take all passable situation , should i store key and pagination number in session . Help me please

Upvotes: 2

Views: 3643

Answers (3)

Rasool Sarfejoo
Rasool Sarfejoo

Reputation: 21

use javascript code for refresh page :


    location.href += ""

or php location to current page

Upvotes: 0

Vignesh
Vignesh

Reputation: 425

As far as i understand you are using a single table instance which is accessed by multiple other html pages. But what i suggest is you can use ajax function to perform delete operation and then you can just call a function to refresh the table alone

bellow is my suggestion not the solution

and here is the php code :

<td><p>".$row['STATUS']."</p></td>
        <td><button class='btn btn-outline-danger' id='btn_Delete' onclick='onDelete()' value='".$row['ORDER_ID']."'><i class='fa fa-minus-circle' aria-hidden='true'></i>
 Delete</button>

the ajax code follows here

 var id = $("#btn_Delete").val();
    $.ajax({
            url: "your php link to delete",
            method: "your methios",
            data: {
                REFERENCE_ID: id,
            },
            success: function(result) {
                UIkit.notification({
                    message: result,
                    status: 'primary',
                    pos: 'top-right',
                    timeout: 5000
                });
                showTable();
            }
        })
        .done(function() {
            console.log("success");
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            console.log("complete");
        });

once done i have called the showtable() function which will automatically refresh the table in the html page without redirecting to another page

This might help you..

Upvotes: 0

younes rami
younes rami

Reputation: 81

You Question is not clear If you want to stay in the page where the code you showed is runing , just delete the last line : header("location:index.php"); if you want it to go back to the page that called replace this

header("location:index.php");

with this

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

If you want to send some parametter , send it with url as id=5 Than replace the id in the header like this

header("location:page.php?id=".$_GET['id'));

I hope this helped you.

Upvotes: 5

Related Questions