php - PDO Fatal Error Check Syntax -


for reason i'm gettin error on second line of included code:

fatal error: uncaught exception 'pdoexception' message 'sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'div='ca' vid='400373'' @ line 1' in /home/stretch045/public_html/scripts/auth.php:12 stack trace: #0 /home/stretch045/public_html/scripts/auth.php(12): pdo->prepare('update users se...') #1 /home/stretch045/public_html/index.php(35): auth->checktoken('94257b73ea4ed51...') #2 {main} thrown in /home/stretch045/public_html/scripts/auth.php on line 12

code

$conn = $this->db; $stmt = $conn->prepare("update users set rating='".$xml->rating."', atc='".$xml->ratingatc."', pilot='".$xml->ratingpilot."', div='".$xml->division."' vid='".$xml->vid."'");  $stmt->execute(); if($stmt->rowcount()==0){      $stmt = $conn->prepare("insert users (vid, fname, lname, rating, atc, pilot, div) values (".$xml->vid.",".$xml->firstname.",".$xml->lastname.",".$xml->rating.",".$xml->ratingatc.",".$xml->ratingpilot.",".$xml->division.")");       $stmt->exec($stmt);      echo 'data inserted db'; } 

div reserved keyword in mysql , needs escaped backticks.

insert users (vid, ..., `div`) values (...) 

Comments