Return to Previous Page after updating

2

I am in an update form and have the link in the link to update, for example: view_fases.php?iddrs=2

I send it to update, and all good the problem comes when I want to finish making the changes I return to the same page with the id that was updated, How could I place it in header depending on the id that was updated :

header("Location:view_fases.php?iddrs="); 
    
asked by laura 16.06.2016 в 20:16
source

2 answers

1

You can do what you mention in the comments of javascript:history.back(-1) , but that can present some problems:

  • If the user has JavaScript disabled, it will not work directly.

  • The user can see a blank window before redirecting to the previous page.

  • JavaScript is an intermediary that is doing something you could do directly with PHP.
  • Doing a history.back(-1) can dislocate the web application (although if this happens, you have more serious problems).

That's why I would recommend that you redirect it directly with PHP, using the function header that you also mention in the question. For what you comment, all you need to do is pass the parameter with the ID. But that's simple if the URL is view_fases.php?iddrs=2 then your code would be something like this:

<?php

    // lee el valor del parámetro iddrs
    $iddrs = $_GET["iddrs"];

    // haz las operaciones que tengas que hacer para la actualización
    // ...

    // redirecciona a la página anterior
    header("Location:view_fases.php?iddrs=" . $iddrs);

An important fact to keep in mind: the redirection with header will give an error if some content has been written before (with echo , print , var_dump , etc.), because it can not be changed the header information once the data output has started.

    
answered by 17.07.2016 в 15:19
0

you must call the GET that is up in the browser bar iddrs=(NUMERO) with a function like this:

header("Location:view_fases.php?$iddrs='.&_GET.'");
    
answered by 17.06.2016 в 02:49