Parse error: syntax error, Unexpected '$error' (T_VARIABLE) in C: xampp htdocs HITSS register.php on line 26

Asked

Viewed 2,490 times

-3

I’m with the title error in my code, can someone give me a light?

<?php $erro = array('1');

include("conexao.php");


    if(isset($_POST['Entrar'])) {

        //1 - REGISTRO DOS DADOS

        if(!isset($_SESSION))
            session_start();

        foreach ($_POST as $chave=>$valor) {
            $_SESSION[$chave] = $mysqli -> real_escape_string($valor);

        //2 - VALIDAÇÃO DOS DADOS


        if(strlen($_SESSION['login']) == 0)
            $erro[] = "Preencha a senha.";

        if(strlen($_SESSION['nome']) == 0)
            $erro[] = "Preencha o nome.";

        if((substr_count($_SESSION['email'], '@') != 1 || substr_count($_SESSION['email'], '.') < 1 || substr_count($_SESSION['email'], '.') > 2)
            $erro[] = "Preencha o e-mail corretamente.";

        if(strlen($_SESSION['nivel'] == 0)
            $erro[] = "Preencha o nivel.";

        if(strlen($_SESSION['cargo']) == 0)
            $erro[] = "Preencha o cargo.";

        if(strlen($_SESSION['nascimento']) == 0)
            $erro[] = "Preencha a data de nascimento.";

        if(strlen($_SESSION['admissao']) == 0)
            $erro[] = "Preencha a data de admissão.";

        if(strlen($_SESSION['senha']) < 8 || strlen($_SESSION['senha']) > 16)
            $erro[] = "Preencha a senha.";

        if(strcmp($_SESSION['senha'], $_SESSION['conf_senha']) != 0
            $erro[] = "Opa, as senhas estão diferentes.";


        //3 - INSERÇÃO NO BANCO

        if(cont($erro) == 0) {


            $sql_code = "INSERT INTO users (
                login, 
                nome, 
                email, 
                nivel, 
                cargo, 
                dat_nasc, 
                dat_adm, 
                foto)
                VALUES(
                '$_SESSION[login]',
                '$_SESSION[nome]',
                '$_SESSION[email]',
                '$_SESSION[nivel]',
                '$_SESSION[cargo]',
                '$_SESSION[nascimento]',
                '$_SESSION[adimissao]',
                '$_SESSION[foto]',
                '$_SESSION[senha]'
                )";
            $confirma = $mysqli- >query($sql_code) or die($mysqli- >error);

            if($confirma) {
                unset($_SESSION[login],
                $_SESSION[nome],
                $_SESSION[email],
                $_SESSION[nivel],
                $_SESSION[cargo],
                $_SESSION[nascimento],
                $_SESSION[adimissao],
                $_SESSION[foto],
                $_SESSION[senha]);

                echo "<scrip> location.href='user_cadastro.php';</script>"
            }
            else {
                $erro[] = $confirma;
            }


        }
        else {
            foreach ($erro as $valor) echo "div class='erro'>"; echo "</div>"; "$valor <br>";
        }

    }


?>
  • Missed ; along those lines? echo "<scrip> location.href='user_cadastro.php';</script>" ?

1 answer

3

You forgot to close some parentheses. See the lines below:

Line 26:

if((substr_count($_SESSION['email'], '@') != 1 || substr_count($_SESSION['email'], '.') < 1 || substr_count($_SESSION['email'], '.') > 2))
    $erro[] = "Preencha o e-mail corretamente.";

Line 29:

if(strlen($_SESSION['nivel'] == 0))
    $erro[] = "Preencha o nivel.";

Line 44:

if(strcmp($_SESSION['senha'], $_SESSION['conf_senha']) != 0)
     $erro[] = "Opa, as senhas estão diferentes.";

On line 49, the function cont does not exist. Probably, you want to use the function count, that serves to count the items of a array.

 if(count($erro) == 0) {

Line 73, do not use spaces in Object Separator

  $confirma = $mysqli->query($sql_code) or die($mysqli->error);

On line 86, you didn’t use ; at the end of the sentence:

 echo "<scrip> location.href='user_cadastro.php';</script>";

And finally, you didn’t close the if that opened on the line 6.

In all sincerity, I advise you to study the syntax of the language, so as not to get lost.

Tip: Use a text editor or IDE that lints your code to see if it has a syntax error.

To find out the error, I used the site PHP Sandbox

  • 2

    In addition to missing one ; on line 85 and line 94 have a foreach poorly formatted, with three instructions without being limited by keys and a string lost, probably because it lacked a echo (and an element <div> without the < from the beginning, which is no problem in PHP), and the order of the values does not make much sense - put the error text out of the element.

Browser other questions tagged

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