Jump to content

Archived

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

hasek522

sql error

Recommended Posts

Here is my sql statement:  I just cant seem to figure out what is wrong with this.

 

$sql = "INSERT INTO accounts (userid,name,description,expenses,profits,balance,starting) VALUES(

'" . $id . "', '"

. $name. "', '"

. $description . "', '"

. 0 . "', '"

. 0 . "', '"

. $_POST['balance'] . "', '".$_POST['balance'].")";

mysql_query($sql) or die(mysql_error());

Here is the 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 'starting) VALUES( '1', 'testsasdas', 'asdasd', '0', '0', '120', '120)' at line 1

Share this post


Link to post
Share on other sites

if you look closly at the error being reported, you will see that the last 120 does not have a closing single tick on it, then go and have a look at your query code you will also see that there is a closing single tick missing after the double ticks before the closing brace......try this

$sql = "INSERT INTO   accounts (userid,name,description,expenses,profits,balance,starting) VALUES(
                     '" . $id   . "', '"
                     . $name. "', '"
                     . $description . "', '"
                     . 0 . "', '"
                     . 0 . "', '"
                     . $_POST['balance'] . "', '".$_POST['balance']."')";
                     mysql_query($sql) or die(mysql_error());

 

Share this post


Link to post
Share on other sites

thanks for the reply, but i tried your code and got this:

 

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 'starting) VALUES( '1', 'Tester123', 'asdasd', '0', '0', '12' at line 1

Share this post


Link to post
Share on other sites

The point where the syntax error was detected is always right after the near ' in the error message. In your case starting is a reserved keyword.

Share this post


Link to post
Share on other sites

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