Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or 'identifier (T_STRING) or variable (T_VARIABLE) or

0

I can not figure out where the error is. I believe it is in the face, but I can not 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

    
asked by anonymous 23.07.2017 / 04:50

1 answer

2

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

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'
    )");
    
23.07.2017 / 04:56