Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/08/2013, 06:09
XD2XD2
 
Fecha de Ingreso: diciembre-2012
Mensajes: 223
Antigüedad: 11 años, 5 meses
Puntos: 2
PDO::quote error

Hola, he empezado con PDO y al insertar un valor para que no realizen inyecciones SQL en la sentencia utilizo $connection->quote($_POST['user'] pero me da el siguiente error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 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 'Mensaje enviado desde el input'', 'password')' at line 1' in C:\xampp\htdocs\index.php:5 Stack trace: #0 C:\xampp\htdocs\index.php(5): PDO->exec('INSERT INTO use...') #1 {main} thrown in C:\xampp\htdocs\index.php on line 5

Código PHP:
Ver original
  1. <?php
  2. if(isset($_POST['submit'])){
  3.     $connection = new PDO("mysql:host=localhost;dbname=PDO","root","");
  4.     $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  5.     $result = $connection->exec("INSERT INTO user(id,username,password) VALUES ('', '".$connection->quote($_POST['user'])."', 'password')");
  6. }
  7. ?>
  8. <form action="" method="post">
  9.     <input name="user">
  10.     <input name="submit" type="submit">
  11. </form>

He buscado en google pero no encontre nada