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

Asked

Viewed 60 times

2

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

Error of analysis:

syntax error, unexpected VALUES (T_STRING) in C: wamp64 www comments insert comment.php on line 10

  • There is an error in the $Insert variable line, ideally you would post the code by text here. I recommend you edit the question and add the code so we can copy it and help you!

  • Remove the last quotes from the Insert line

  • ok I will change my post

2 answers

2

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

Lack also ( and ) between the fields being inserted, nome, comentario.

Should be like this:

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

On the line of query 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 since it was marked as obsolete and was removed in PHP 5.3.0.

-2

On the line:

$insert = "INSERT INTO comentarios_tb nome, comentario"

Missing one ;.

Browser other questions tagged

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