Parse error: syntax error, Unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or Identifier (T_STRING) or variable (T_VARIABLE) or

Asked

Viewed 2,546 times

0

I can’t figure out where the mistake is. I believe it’s on my face, but I can’t find it!

$inserir = $conexao->query("INSERT INTO cadastro (nome, sobrenome, email, senha, contrata, trabalha, status) VALUE (
          $_POST['nome'],
          $_POST['sobrenome'],
          $_POST['email'],
          $_POST['senha'],
          $_POST['contrata'],
          $_POST['trabalha'],
          'N'
    )");

Parse error: syntax error, Unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or Identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in

  • 2

    Put all POST values between keys.

  • @Andersoncarloswoss I’ll do it, but why between keys? It wasn’t like that...

  • You are trying to inject a PHP expression into a string. In order for PHP to understand that it is an expression, you need to use the keys.

  • https://answall.com/q/217819/5878

1 answer

3


I believe the problem is that it is not identifying the variables correctly.

Try passing them using concatenation:

$inserir = $conexao->query("INSERT INTO cadastro (nome, sobrenome, email, senha, contrata, trabalha, status) VALUE (
          '".$_POST['nome']."',
          '".$_POST['sobrenome']."',
          '".$_POST['email']."',
          '".$_POST['senha']."',
          '".$_POST['contrata']."',
          '".$_POST['trabalha']."',
          'N'
    )");

Or as Anderson suggested, using keys in variables:

$inserir = $conexao->query("INSERT INTO cadastro (nome, sobrenome, email, senha, contrata, trabalha, status) VALUE (
          '{$_POST['nome']}',
          '{$_POST['sobrenome']}',
          '{$_POST['email']}',
          '{$_POST['senha']}',
          '{$_POST['contrata']}',
          '{$_POST['trabalha']}',
          'N'
    )");
  • 1

    And probably missing the simple quotes there to define as string in Mysql.

  • It worked, but there was this mistake Fatal error: Uncaught Error: Call to a member function close() on boolean in

  • 1

    That’s another completely different problem.

  • @Tiago I think this has nothing to do with the query referenced in the question, see the error line. If you cannot solve, I recommend that create another question.

Browser other questions tagged

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