tcrabtree
tcrabtree

Reputation: 21

PHP PDO Insert problem

I've hit a wall with a PDO insert:

$q = $dbh->prepare('INSERT INTO grant (grant_name, update) VALUES (?,?)');
$q->bindParam(1, $grant_name, PDO::PARAM_STR);
$q->bindParam(2, $update, PDO::PARAM_STR);
$q->execute();

I get an error:

 PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; 

But I cannot find the problem. I have tried using placeholder (such as :grant_name) and using the question marks (?).

Upvotes: 2

Views: 502

Answers (2)

Brad
Brad

Reputation: 163262

Both GRANT and UPDATE have specific meanings in SQL. Try this:

$q = $dbh->prepare('INSERT INTO `grant` (`grant_name`, `update`) VALUES (?,?)');

Upvotes: 6

Paul Sonier
Paul Sonier

Reputation: 39480

Having a column name of UPDATE would appear to be your problem. Try quoting the column name (or changing the column name to something that's not a reserved word).

Upvotes: 1

Related Questions