MySQLi error INSERT [duplicate]

-1

I'm not sure how to identify the error. I've always built such structures, but now that error is appearing.

  

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

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

I'M USING THESE VERSIONS:

     

PHP = 7.1.6

     

MySQL = 5.7.11

    
asked by anonymous 23.07.2017 / 18:05

1 answer

2

The concatenation of the arrays inside the double quotation marks is incorrect. PHP does not understand functions and arrays that are inside double quotation marks as variables. The correct way is to concatenate with keys: {$_POST['chave']} or this way: "string".$_POST['chave']."string";

Another remark, your query is VALUE and the correct one is VALUES in the plural.

Result:

$senha = password_hash($_POST['senha'], PASSWORD_DEFAULT);
$sql = "INSERT INTO cadastro (nome, sobrenome, email, senha, contrata, trabalha, status) VALUES (
       {$_POST['nome']},
       {$_POST['sobrenome']},
       {$_POST['email']},
       $senha,
       {$_POST['contrata']},
       {$_POST['trabalha']},
       'N'
      )";

    echo $sql;

Follow Here a link to the Sandbox

    
24.07.2017 / 16:34