Log in

View Full Version : Invalid sql INSERT


Nullifi3d
02-28-2006, 09:32 PM
$db->query_write("INSERT INTO " . TABLE_PREFIX . "armyintelreports (id, time, from, target, type, result, spies_sent, spies_caught, sab_item, sab_amount) VALUES ('{$report['id']}', " . TIMENOW . ", '{$vbulletin->userinfo['username']}', '{$vbulletin->GPC['username']}', 'sab', '{$report['result']}', '{$vbulletin->GPC['spies']}', '{$report['caught']}', '{$report['item']}', '{$vbulletin->GPC['amount']}')");


I don't understand why this isn't working.

Database error in vBulletin 3.5.3:

Invalid SQL:
INSERT INTO armyintelreports (id, time, from, target, type, result, spies_sent, spies_caught, sab_item, sab_amount) VALUES ('37', 1141168830, 'Nullified', 'jasondoe', 'sab', 'Aborted', '1', '0', 'Indestructable Shield', '1');

MySQL Error : 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 'from, target, type, result, spies_sent, spies_caught, sab_item, sab_amount) VALU' at line 1
Error Number : 1064

never mind. had to wrap the from and type fields in `.

Marco van Herwaarden
03-01-2006, 01:01 PM
never mind. had to wrap the from and type fields in `.
No, you should just not use reserved words like 'from'. Wrapping them in ` is just ignoring the symptoms.

Nullifi3d
03-01-2006, 01:11 PM
I have changed the fields, but what symptoms are you referring to?

Marco van Herwaarden
03-01-2006, 01:30 PM
Symptoms = the error message.

Adding ` around them only removes the symptom (the error)
Renaming them is removing the cause of the error (and will prevent future problems like running in strict mode or trying to export/import your database).

Nullifi3d
03-01-2006, 05:22 PM
k, thanks for the heads up.