Jump to content

Weird Syntax mysql error..


newman445617

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/166556-weird-syntax-mysql-error/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.