For the following problem I have as an object practice to send a form to MySQL; my code, which is by the PDO method, does not mark errors. So when I fill in the fields, when I run the code, the machine tells me that the insertion of data was correct, but when I look at the database, it does not contain anything, no matter how much I actulize. I repeat the procedure with different data but it is the same. So my question is: What could be failing?
This is the connection to the server.
<?php
$PDO = new PDO(
'mysql:host=localhost;dbname=db_mensajes;charset=UTF8','root','' );
try {
echo "mensaje enviado";
$sql=$PDO->prepare("INSERT INTO usuarios( nombre, clave, mensaje) VALUES (
:nombre, :clave, :mensaje)");
$sql->bindParam(':nombre',$_POST['nombre']);
$sql->bindParam(':clave',$_POST['clave']);
$sql->bindParam(':mensaje',$_POST['mensaje']);
$sql->execute();
}catch(PDOexception $e) {
echo "mensaje no enviado:".$e ->GetMessaje();
}
?>
This is the form.
<form method="POST" action="insertar.php">
<h1>Envio de mensaje</h1>
<label>Nombre:</label>
<input type="text" required="" placeholder="escribe tu nombre"><br><br>
<label>Clave:</label>
<input type="password" required="" placeholder="escribe tu clave"><br><br>
<label>Mensaje:</label>
<textarea required="" placeholder="escribe tu mensaje"></textarea><br><br>
<input type="submit" value="Enviar mensaje">
</form>