I am creating a comment system in PHP, but at the conclusion of the work I came across the following error:

1

Code:

<?php include "connection.php"; ?>

<?php
$nome=$_POST['nome'];
$comentario=$_POST['comentario'];
?>

<?php 
$insert = "INSERT INTO comentarios_tb nome, comentario"
VALUES('$nome', '$comentario')";
$sql = mysqli_master_query($insert);
echo "<center><h3>Obrigado, seu comentário foi enviado!</center>";
?>

Parse error:

  

Syntax error, unexpected 'VALUES' (T_STRING) in C: \ wamp64 \ www   \ comment \ insert comment.php on line 10

    
asked by anonymous 28.09.2017 / 08:58

2 answers

1

Your insert instruction has got a " more in the middle. As it is divided into two lines it becomes more difficult to see.

( and ) is also missing between the fields that are being inserted, nome, comentario .

It should look like this:

$insert = "INSERT INTO comentarios_tb (nome, comentario)  VALUES('$nome', '$comentario')";
//------------------------------------------------------^ sem " aqui porque já está ----^ aqui

In the query line, the connection is missing and should be:

$sql = mysqli_master_query($conn, $insert);
//--------------------------^ conexão agora aqui

You should also consider not using mysqli_master_query because it was marked obsolete and was removed in PHP 5.3.0.

    
28.09.2017 / 11:23
-2

On line:

$insert = "INSERT INTO comentarios_tb nome, comentario"

A ; is missing.

    
28.09.2017 / 11:04