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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.