database - PHP PDO: Syntax error or access violation (Help) -
this question has answer here:
i have problem pdo , can't find solution:
my function:
public static function create($position, $name, $mail, $mailtext, $confirmed, $key, $formid) { global $database; try { $pdo_result = $database->prepare('insert form (position, name, mail, mailtext, confirmed, key, form_idform) values(:position, :name, :mail, :mailtext, :confirmed, :key, :form_idform)'); $pdo_result->execute(array( ':position' => $position, ':name' => $name, ':mail' => $mail, ':mailtext' => $mailtext, ':confirmed' => $confirmed, ':key' => $key, ':form_idform' => $formid )); return $database->lastinsertid(); } catch(pdoexception $e) { page::error('error: message:', $e->getmessage()); } return null; }
exception: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'key, form_idform) values('position', 'name', 'mail', 'mailtext', '1', 'keeey', '' @ line 1
you're using reserved words in field names.
try escaping insert
-statement within $database->prepare
-construct this:
insert form ( `position`, `name`, `mail`, `mailtext`, `confirmed`, `key`, `form_idform`) ....
Comments
Post a Comment