newman445617 Posted July 19, 2009 Share Posted July 19, 2009 Hi everyone, $query = 'INSERT INTO cashlogs (from, userid, page, amount, to, time, data) VALUES(\''.$db->escape($pun_user['username']).'\', \''.$db->escape($pun_user['id']).'\', \'test\', \'Sent\', \''.$user['username'].'\', \''.$time.'\', \''.number_format($amount, 2, '.', ',').'\')'; $db->query($query) or error('Unable to add log', __FILE__, __LINE__, $db->error()); And I am getting this error: Database reported: 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, userid, page, amount, to, time, data) VALUES('newman', '2', 'test', 'S' at line 1 (Errno: 1064) Failed query: INSERT INTO cashlogs (from, userid, page, amount, to, time, data) VALUES('newman', '2', 'test', 'Sent', 'mike', '1248043936', '25.00') Honestly i am lost am i missing something? Everything seems fine in phpmyadmin and stuff. Quote Link to comment https://forums.phpfreaks.com/topic/166556-weird-syntax-mysql-error/ Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 from is a mysql reserved word. mysql will allow you to use reserved words as column or table names if you wrap it in backticks `from` but the better solution would be not to use reserved words to begin with. Quote Link to comment https://forums.phpfreaks.com/topic/166556-weird-syntax-mysql-error/#findComment-878320 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 also, when you get that sorted out, you're going to find yourself having that same error for a couple of those other columns, as well. Wash, rinse and repeat for them. Quote Link to comment https://forums.phpfreaks.com/topic/166556-weird-syntax-mysql-error/#findComment-878321 Share on other sites More sharing options...
newman445617 Posted July 19, 2009 Author Share Posted July 19, 2009 also, when you get that sorted out, you're going to find yourself having that same error for a couple of those other columns, as well. Wash, rinse and repeat for them. Huh? This is basic mysql not working? I'm lost sir. Quote Link to comment https://forums.phpfreaks.com/topic/166556-weird-syntax-mysql-error/#findComment-878323 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 In your query, you are using a column named "from" well "from" is a reserved word, part of the mysql syntax. It's like naming one of your columns the name "select" or "insert" well that's a keyword that mysql uses to perform queries. So mysql is getting confused, thinking you are trying to use as such. You can tell mysql to treat it as a column by wrapping backtics around it like so: `from` but you shouldn't do that. Instead, you should pick a column name that is not a reserved word. Quote Link to comment https://forums.phpfreaks.com/topic/166556-weird-syntax-mysql-error/#findComment-878325 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.