Reputation: 339
I am trying to execute an SQL query but was returned with an error below:
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 '' at line 1
$option = Tools::getValue('option');
$sql = 'INSERT INTO `'._DB_PREFIX_.'slot` VALUES ('.(int)$params['cart']->id.', '.$option.') ON DUPLICATE KEY UPDATE id_slot='.$option;
Db::getInstance()->execute($sql);
Upon checking in database, it was actually executed and ran successfully. But on the front-end, I was thrown the error above. I am using the hook below to execute my codes:
I have tried $option = (int)pSQL(Tools::getValue('option')); but it returns 0 on save.
Any ideas?
Upvotes: 0
Views: 606
Reputation: 1447
If your value is integer: you have to use (int) before $option
If your value is string:
$option = Tools::getValue('option');
$sql = 'INSERT INTO `'._DB_PREFIX_.'slot` VALUES ('.(int)$params['cart']->id.', "'.pSQL($option).'") ON DUPLICATE KEY UPDATE id_slot='.$option;
Db::getInstance()->execute($sql);
Upvotes: 1