I can not go to another page with the header function

1

I'm having problem with header() , I made a schedule to change the data in the database and when I click the button to be able to change it goes to a blank page so I put header("Location: AdmAgenda.php"); so that it could go back to the page already with data updated but giving error:

  

The localhost page is not working

     

Excess redirect by localhost Try to clear cookies.

What can I do to fix it?

My code:

<?php 
$idSeg = filter_input(INPUT_GET, "id-segunda");
$seg = filter_input(INPUT_GET, "seg");

$idTerca = filter_input(INPUT_GET, "id-ter");
$tercaa = filter_input(INPUT_GET, "ter");


$idQuarta = filter_input(INPUT_GET, "id-quarta");
$quartaa = filter_input(INPUT_GET, "qua");


$idQuinta = filter_input(INPUT_GET, "id-quinta");
$quintaa = filter_input(INPUT_GET, "qui");

$idSexta = filter_input(INPUT_GET, "id-sexta");
$sextaa = filter_input(INPUT_GET, "sex");

$idSabado = filter_input(INPUT_GET, "id-sabado");
$sabadoo = filter_input(INPUT_GET, "sab");


include("conexao.php");


if($link) {
    $segg = mysqli_query($link, "UPDATE horas_segunda set horas_de_segunda='$seg' where id='$idSeg';");
    $terc = mysqli_query($link, "UPDATE horas_terca set horas_de_terca='$tercaa' where id='$idTerca';");
    $quarr = mysqli_query($link, "UPDATE horas_quarta set horas_de_quarta='$quartaa' where id='$idQuarta';");
    $quinn = mysqli_query($link, "UPDATE horas_quinta set horas_de_quinta='$quintaa' where id='$idQuinta';");
    $sexx = mysqli_query($link, "UPDATE horas_sexta set horas_de_sexta='$sextaa' where id='$idSexta';");
    $sabaa = mysqli_query($link, "UPDATE horas_sabado set horas_de_sabado='$sabadoo' where id='$idSabado';");
    header("Location: AdmAgenda.php");
}
else{
    die("Erro: " .mysqli_error($link));
}
?>
    
asked by anonymous 17.01.2017 / 04:07

2 answers

1

I do not agree with the way you're doing things, because just redirecting will not give the information "Update performed successfully" to the user, but if you change:

if($link) {

To:

if($link && isset($_GET["seg"])) { 

Already solves the problem the way you want it.

    
17.01.2017 / 04:29
0

Although not the best practice, it's okay to redirect to the same page as long as you know what you're doing and can write your logic in a way that never falls into infinite redirection (the browser actually cancels the loop when verifying that there are many redirects to the same page, casting something like ERR_TOO_MANY_REDIRECTS ). Thus, it does not stop the navigation.

In your specific problem, you're just checking to see if the variable $link (which by context, it turns out that it's an open connection with mysql ) is not null , that is: always (if all is right).

To avoid this, instead of checking for a connection, make sure the url is sending the parameters to save. I suggest putting above your if($link) { something like this:

if ( $idSeg && $seg && $idTerca && $tercaa && $idQuarta && $quartaa &&
     $idQuinta && $quintaa && $idSexta && $sextaa && $idSabado && $sabadoo ) {

    if($link) {
        /* funções de update */
        header("Location: AdmAgenda.php");
    } else{
        die("Erro: " .mysqli_error($link));
    }

}

This would involve just updating the database and redirecting if all of these parameters are present (I do not know if this is the logic of your application, but it is only for the purpose of explanation, you adapt). A more clean approach is to check one by one. When you redirect, the parameters will not be sent and consequently will not fall in this if .

    
17.01.2017 / 04:33