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!