TheStalker Posted February 28, 2008 Share Posted February 28, 2008 hi, i am having trouble making an insert statment work. i know the database is conected etc because i have other staments working above the one i am having trouble with. I have a large if esle stament that produces a total sorted in a variable called $total i am trying to insert the total into table accounts into collum WeelyCharge. the code i have is as follows $sql = "INSERT INTO accounts WeeklyCharge VALUES $total"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } the error i seem to get is this 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 'WeeklyCharge VALUES 18.2' at line 1 i have tried many diffrent ways of doing this and still cant get this insert to work. If anyone has any ideas that would be great many thanks! Quote Link to comment Share on other sites More sharing options...
premiso Posted February 28, 2008 Share Posted February 28, 2008 $sql = "INSERT INTO accounts (WeeklyCharge) VALUES ($total)"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } Try that. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 28, 2008 Share Posted February 28, 2008 Or $sql = "INSERT INTO accounts (WeeklyCharge) VALUES ('$total')"; Quote Link to comment 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.