-1

I'm getting an error with PDO:

PDOStatement::execute() [pdostatement.execute]: 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, pseudo, ip, date) VALUES ('mykeyperso', 'mrthebigbosseur', '86.208.78.145',' at line 1 in /home/a1394006/public_html/api/skype.php on line 51

And I don't know why

My source code:

 $req = $bdd->prepare('INSERT INTO logs (key, pseudo, ip, date) VALUES (:key, :pseudo, :ip, :date)');
$req->bindParam(":key", $key1, PDO::pARAM_STR);
$req->bindParam(":pseudo", $pseudo1, PDO::pARAM_STR);
$req->bindParam(":ip", $ip1, PDO::pARAM_STR);
$req->bindParam(":date", $date, PDO::pARAM_STR);
$req->execute(); 

My variable:

 $key1 = $_GET['key'];
$pseudo1 = $_GET['pseudo'];
$ip1 = $_SERVER['REMOTE_ADDR'];
$date = $_SERVER['REQUEST_TIME']; 

My database: http://prntscr.com/6zjsmd

So if someone can help me plz

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

1

Key is a reserved word in mysql. To use it as a column name, wrap it in backticks (`key`). Double quotes would apparently also work in ANSI SQL mode.

Jonnix
  • 4,121
  • 1
  • 30
  • 31