How to redirect to the same page after deleting a record?

0

Greetings, I am trying to redirect to the same page after having deleted a record, the page that shows me the table with the data of which I choose to delete this at this address:

/SA/admin/info_student.php?ver_curso_eli=&id_alumno=1

What I want is that by pressing the button of a record, after it is deleted I redirect to the page with that student ID = 1 to continue seeing the data of that student. I will leave the function that deletes the record:

$id = $_GET['id'];
$query = "DELETE FROM inscritos WHERE id = '$id'";
$sql = $mysqli->query($query);

if($sql>0):
header('Location: AQUI ES DONDE DEBERÍA COLOCAR EL ID DE ESE ALUMNO');
else:
echo mysqli_error($mysqli);
endif;

I clarify that the id that I receive with GET in the delete function is not the id of the student, it is the id of the record that I am deleting. Thank you very much to anyone who can help me with this doubt.

    
asked by Alejo Mendoza 28.08.2017 в 21:01
source

3 answers

1

If you want to return to the previous page, according to your comments I think that is what you wanted:

 //opcion 1
   window.history.back()
//opcion 2
   location.href = document.referrer
//O con php
   $url = $_SERVER['HTTP_REFERER'];
   header("LOCATION:$url");
    
answered by 29.08.2017 в 01:26
0

you want to delete the student's id again redirect to the same file to see all the data again (assuming that is so, I do not know if it works in this way)

 header('Location: /SA/admin/info_student.php?ver_curso_eli=&id_alumno');
    
answered by 29.08.2017 в 00:41
0

I understand that you have a page that shows the data and the student's enrollments that you arrive with the URL /SA/admin/info_student.php?ver_curso_eli=&id_alumno=1

Then on that page you have a list of the student's entries and I imagine that each item on the list contains a link to delete that entry, that link contains the ID of the entry you want to delete.

Clicking on the link executes the script that takes the registration ID and issues the statement DELETE ...

In this scenario I propose two options:

  • Also pass the ID of the student in the URL that leads to the deletion script, so that after deleting you can return to the student's page again using the URL /SA/admin/info_student.php?ver_curso_eli=&id_alumno=1

  • Before doing the deletion queries to the database the ID of the student to which the inscription that you are deleting belongs. You save the ID in a variable and after executing the delete statement you do the redirect with the ID obtained as in case 1. This solution implies an additional query to the database but it is more universal because it allows you to delete an entry from any site , for example from a course view, a list of last registrations made, etc.

  • answered by 06.07.2018 в 09:02