Matt
Matt

Reputation: 7192

PDO insert error

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!

Upvotes: 1

Views: 1383

Answers (1)

ircmaxell
ircmaxell

Reputation: 165193

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()

Upvotes: 2

Related Questions