简体   繁体   中英

PDO insert not inserting with multiple values

So I have some data that I'm trying to enter with PDO. Here's what my code looks like

$DATA = $con->prepare("INSERT INTO users (key, ip) VALUES (:key, :ip)");
$DATA->bindValue(':ip', $ip, PDO::PARAM_STR);
$DATA->bindValue(':key', $key, PDO:PARAM_STR);
$DATA->execute();

The issue is it won't enter into the DB. It only works when I do one value like this

$DATA = $con->prepare("INSERT INTO users (key) VALUES (:key)");

Is this normal? Do I do individual statements for each variable?

My DB

+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| key   | varchar(255)     | YES  |     | NULL    |                |
| ip    | varchar(255)     | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+

I get the 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 'key, ip) VALUES ('53a786577de99', 'E6pdpExv6q363baea9cba210afac6d7a556fca596e30c' at line 1' in /Users/mike/Desktop/Mail/index.php:37 Stack trace: #0 /Users/mike/Desktop/Mail/index.php(37): PDOStatement->execute() #1 {main} thrown in /Users/mike/Desktop/Mail/index.php on line 37

我想如果我想起的话,KEY是一个保留字。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM