Parse error: syntax error, unexpected '$ error' (T_VARIABLE) in C: \ xampp \ htdocs \ HITSS \ cadastrar.php on line 26 [closed]

-3

I'm having the title error in my code, can anyone 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>";
        }

    }


?>
    
asked by anonymous 09.07.2018 / 15:53

1 answer

2

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.";

At line 49, the cont function does not exist. You probably want to use the count function, which is used to count the items of a array .

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

Line 73, do not use spaces in the Object Separator

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

At line 86, you did not use ; at the end of the sentence:

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

And, finally, you did not close the if that opened on the 6 line.

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

Tip : Use a text editor or IDE that does a lint of your code, to see if it has a syntax error.

To find out the error, I used PHP Sandbox

    
09.07.2018 / 15:56