Error Parse error: syntax error, Unexpected ';' in C: xampp htdocs adoption backend valida.php on line 32

Asked

Viewed 231 times

-4

Guys I’m not finding the mistake please someone help me:

<?php
session_start();    
//Incluindo a conexão com banco de dados
include_once("conexao.php");    
//O campo usuário e senha preenchido entra no if para validar
if ((isset($_POST['email'])) && (isset($_POST['senha']))) 
{
    $usuario = mysqli_real_escape_string($con, $_POST['email']); //Escapar de caracteres especiais, como aspas, prevenindo SQL injection
    $senha = mysqli_real_escape_string($con, $_POST['senha']);
    $senha = $senha;

    //Buscar na tabela usuario o usuário que corresponde com os dados digitado no formulário
    $result_usuario = "SELECT * FROM usuario WHERE email = '$usuario' && senha = '$senha' LIMIT 1";
    $resultado_usuario = mysqli_query($con, $result_usuario);
    $resultado = mysqli_fetch_assoc($resultado_usuario);

    //Encontrado um usuario na tabela usuário com os mesmos dados digitado no formulário
    if (isset($resultado)) 
    {           
        $_SESSION['usuarioId'] = $resultado['id_usuario'];
        $_SESSION['usuarioNome'] = $resultado['nome'];
        $_SESSION['usuarioNiveisAcessoId'] = $resultado['niveis_acesso_id'];
        $_SESSION['usuarioEmail'] = $resultado['email'];

        if ($_SESSION['usuarioNiveisAcessoId'] == "1")
        {
            header("Location: administrativo.php");
            exit;
        }
        else ($_SESSION['usuarioNiveisAcessoId'] == "2")
        {
            header("Location: colaborador.php");
            exit;
        }

    }
    //Não foi encontrado um usuario na tabela usuário com os mesmos dados digitado no formulário
    //redireciona o usuario para a página de login
    else {
        //Váriavel global recebendo a mensagem de erro
        $_SESSION['loginErro'] = "Usuário ou senha Inválido";
        header("Location: index.php");
    }
//O campo usuário e senha não preenchido entra no else e redireciona o usuário para a página de login
} 

else
{
    $_SESSION['loginErro'] = "Usuário ou senha não preenchidos";
    header("Location: index.php");
}
?>
  • which is line 32?

  • header("Location: contributor.php");

  • Emmanuel, welcome to Sopt! It seems that your question is incomplete, give more information about your project so that we can help you. If you have questions about how the site works, see tour and take a look over how to ask a good question

  • 1

    @bio this is a typo, no need more information beyond the code and the returned error. Only it seems that the code that this in question is not the same as the file, because if the line 32 is the header("Location: colaborador.php"); it is not the error, because it contains the point and comma.. Only a detail that is not necessary exit; when you are making a redirect. I voted to close the question, look closely at your files and see where it is missing ;

  • @wmsouza I found the question vague and poorly structured both in title and content, after all, nor the line number he had informed, but I will not extend my arguments.

  • In the title, this is the error that in the end has line 32.

  • @wmsouza and what line is in the code? He had to report later...

Show 2 more comments

2 answers

2

Change Else for elseif

if ($_SESSION['usuarioNiveisAcessoId'] == "1")
{
    header("Location: administrativo.php");
    exit;
 }
 elseif ($_SESSION['usuarioNiveisAcessoId'] == "2")
 {
    header("Location: colaborador.php");
    exit;
 }
  • It seemed to have solved but is now redirecting to the page: http://localhost/adoption/backend/loginusuario.php but this page only exists at the root.

2


Young man, the mistake is that you put an expression on else. There is no expression in else.

If you need to use a conditional second expression, use elseif.

Example:

if (expressao) {
    // bla
} elseif (outra_expressao) {
    //ble
}
  • 2
  • It seemed to have solved but is now redirecting to the page: localhost/adoption/backend/loginusuario.php but this page only exists at the root.

  • @Emmanuelsiqueira in this case, if the error is another, you need to ask another question on the site.

  • 1

    @Emmanuelsiqueira check the logic of your code, if you have any other error, open another question. If the answer met your specific problem, put it as Accepted. Read more [Ask]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.