I know there are hundreds of similar questions out there, If my answer is out there, I haven't been able to work it out yet...
I have some PHP, I'm using PDO to update a table in mySQL
when I do I get an uncaught PDO exception.
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 MariaDB server version for the right syntax to use near 'mouse, CatID=1 WHERE ID=1' at line 1' in C:\xampp\htdocs\classes\catalogue.php:93 Stack trace:
The method looks like this:
function editItem($item){
$d = JSON_decode($item, true);
var_dump($d);
$name = $d['Name'];
$price = $d['Price'];
$desc = $d['Desc'];
$catID = $d['CatID'];
$ID = $d['ID'];
$conn = self::connect();
$sql = "UPDATE catalogue SET Name=$name, Price=$price, `Desc`=$desc, CatID=$catID WHERE ID=$ID";
// Prepare statement
$stmt = $conn->prepare($sql);
// execute the query
$stmt->execute();
}
the var_dump looks like this:
array(7) {
["ID"]=>
string(1) "1"
["Name"]=>
string(5) "Mouse"
["Price"]=>
int(20)
["Desc"]=>
string(7) "A mouse"
["CatID"]=>
string(1) "1"
["$$hashKey"]=>
string(9) "object:75"
["edit"]=>
bool(true)
}
Clearly I've missed something obvious, I just can't work it out.... Can anyone see where I wen't wrong?
thanks