syntax error, unexpected 'else' (T_ELSE) [closed]

0

Code with the error:

if(!empty($_GET['horarios'])){
        $cod_hor=$_GET['horarios'];
    }else{
        header('Location:error.php');
    }

    if($_SESSION['tipo_pro']=='a' or $_SESSION['tipo_pro']=='p'){
        $profesor=$_SESSION['ced_pro'];

        $pa=mysql_query("SELECT * FROM horarios WHERE ced_pro='$profesor' and cod_hor='$cod_hor'");             
        if($row=mysql_fetch_array($pa)){
            $oNivel=new Consultar_Nivel($row['cod_niv']);
            $nombre_horario=$oNivel->consultar('nivel').'.'.$row['horario'];
          }else{
            header('Location:error.php');

      }else{
    header('Location:error.php');
    }
    }
    
asked by Genesis 05.11.2016 в 04:24
source

1 answer

2

I would say that the main problem is that you do not indentify your code. And as a result, it is very easy to omit a { or } somewhere.

In this particular case, the following combination of statements is incorrect:

    }else{
      header('Location:error.php');

}else{

It is equivalent to:

if (...) {
} else {
} else { /* el segundo else es ilegal */
}

.. you can not define 2 else in one condition.

Again, because you do not have good indentation of your code, it is difficult to know exactly what was your intention. But I assume you need a } between 2 else :

    }else{
      header('Location:error.php');
    } /* tal vez te faltó esto aquí */
}else{
    
answered by 05.11.2016 / 04:35
source