tags:

views:

14

answers:

1

I'm trying to get the code below to work.....

The error:

ERRORSQLSTATE[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 '?, ?, ?, ?)' at line 1

The code:

$data=array($idApplications,$author,$addedOn,$note);
try {
    $STH = $this->DBH->query('
      INSERT INTO '.$table.' (idApplications,Author,NoteAddedOn,Note) 
      VALUES (?, ?, ?, ?)
   ');
    $STH->execute($data);
}
catch(PDOException $e) {echo $e->getMessage();}
}   

(Using PHP PDO and MySQL)

Any help would be appreciated!

Thanks!

+2  A: 

The problem is that you're trying to prepare a statement, yet you're executing it (via query()) instead of preparing it.

Change ->query(...); to ->prepare(...); and leave the rest as is...

PDO::Prepare()

ircmaxell
Ah! That solved it. Thanks! :) (As you can tell, I'm still learning PDO!)
Matt
No problem. We all make mistakes. The only thing we can do is try to learn from them...
ircmaxell