0

I am getting an error in my SQL for my code but for the life of me, I can't seem to understand how to fix it. the error code in SQL is:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[value-1],[value-2],[value-3],[value-4])' at line 1

from: INSERT INTO mensajes(id, nombre, email, mensaje) VALUES ([value-1],[value-2],[value-3],[value-4])

My code is as follows:

    if ( isset($_POST["nombre"],$_POST["email"],$_POST["mensaje"]) and $_POST["nombre"]!="" and $_POST["email"]!="" and $_POST["mensaje"]!=""){

    // Traspasamos a variables locales, para evitar complicaciones con las comillas:
    $nombre = $_POST["nombre"];
    $email = $_POST["email"];
    $mensaje = $_POST["mensaje"];

    // Preparamos la orden SQL:
    $consulta = "INSERT INTO mensajes(id,nombre,email,mensaje) VALUES('0','$nombre','$email','$mensaje')";

    if ( mysqli_query($con, $consulta) ){

        echo "<p>Registro agregado.</p>";

    } else {

        echo "<p>No se agregó...</p>";

    }

} else {

    echo '<p>Por favor, complete el <a href="formulario.html">formulario</a></p>';

}

} else {

echo "<p>Servicio interrumpido</p>";

}

Any help on this would be great and if I need to provide more information, also, please let me know. Cheers!

Shadow
  • 33,525
  • 10
  • 51
  • 64
Erik James Robles
  • 721
  • 2
  • 12
  • 24
  • Hi @Erik James Robles did you check database connection string? one more thing check your code with Exception handling. or use code from below link https://www.w3schools.com/php/php_mysql_insert.asp – Raju Dudhrejiya Feb 09 '18 at 06:37
  • @RajuDudhrejiya Thank you. Exception handling was off. Switched from Mamp to Xampp and was able to isolate problem much more easily. – Erik James Robles Feb 16 '18 at 11:45

0 Answers0