I am trying to insert a new record into a mysql database and get the following 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 '30, 60, 90, DayCreated) VALUES ( 'Rush Shirt', '6-30-09','7-30-09','8-30-09','5-' at line 1

Using this code in php:

$sql = "INSERT INTO table_name ( FeeName, 30, 60, 90, DayCreated)
VALUES ( '$_POST[txtFee]', '$_POST[txt30]','$_POST[txt60]','$_POST[txt90]','$_POST[txtDayC]' )";

I searched the forums and the internet and couldn't find the correct syntax to fix this :(

Well I found out that you cant have just numbers as column names.. So I changed that around and it worked..

Solution:

$sql = "INSERT INTO Admin ( FeeName, Day30, Day60, Day90, DayCreated) 
VALUES
( '".$_POST[txtFee]."', '".$_POST[txt30]."','".$_POST[txt60]."','".$_POST[txt90]."','".$_POST[txtDayC]."')";

<offtopic> You should also consider using mysql_real_escape_string to prevent any kinda sql injections. </offtopic> :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.