Reputation:
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
Upvotes: 2
Views: 134