morocco-iceberg Posted June 18, 2010 Share Posted June 18, 2010 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 '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) VALUES ('d' at line 1 if(isset($_POST["add"])){ $section = "sent"; $level = $_POST["level"]; $table = $section . $level; $section_0 = $_POST["0"]; $section_1 = $_POST["1"]; $section_2 = $_POST["2"]; $section_3 = $_POST["3"]; $section_4 = $_POST["4"]; $section_5 = $_POST["5"]; $section_6 = $_POST["6"]; $section_7 = $_POST["7"]; $section_8 = $_POST["8"]; $section_9 = $_POST["9"]; $section_10 = $_POST["10"]; $section_11 = $_POST["11"]; $section_12 = $_POST["12"]; $section_13 = $_POST["13"]; $section_14 = $_POST["14"]; $section_15 = $_POST["15"]; $section_16 = $_POST["16"]; $section_17 = $_POST["17"]; $section_18 = $_POST["18"]; $section_19 = $_POST["19"]; $query = "INSERT INTO $table (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) VALUES ('$section_0', '$section_1', '$section_2', '$section_3', '$section_4', '$section_5', '$section_6', '$section_7', '$section_8', '$section_9', '$section_10', '$section_11', '$section_12', '$section_13', '$section_14', '$section_15', '$section_16', '$section_17', '$section_18', '$section_19')"; mysql_query($query) or die(mysql_error()); $success_message = "Question was added."; } I can't find anything wrong, but no matter what it won't work. Help! Quote Link to comment https://forums.phpfreaks.com/topic/205160-sql-syntax-error-i-cant-fix-it/ Share on other sites More sharing options...
Adam Posted June 18, 2010 Share Posted June 18, 2010 Can you echo out $query and post the SQL? Quote Link to comment https://forums.phpfreaks.com/topic/205160-sql-syntax-error-i-cant-fix-it/#findComment-1073878 Share on other sites More sharing options...
mentalist Posted June 18, 2010 Share Posted June 18, 2010 I want to ask if your tables' field names are 0, 1, 2, etc... (i'm pretty sure names can't start with numerics! So check to see if your table was created...) Just try replacing this line if the table exists and your wanting to access the table like an array: $query = "INSERT INTO $table VALUES ('$section_0', '$section_1', '$section_2', '$section_3', '$section_4', '$section_5', '$section_6', '$section_7', '$section_8', '$section_9', '$section_10', '$section_11', '$section_12', '$section_13', '$section_14', '$section_15', '$section_16', '$section_17', '$section_18', '$section_19')"; Quote Link to comment https://forums.phpfreaks.com/topic/205160-sql-syntax-error-i-cant-fix-it/#findComment-1073883 Share on other sites More sharing options...
Adam Posted June 18, 2010 Share Posted June 18, 2010 i'm pretty sure names can't start with numerics! Actually they can. Edit: Although you may be on the right track there. Try adding grave accents (`) around the field names.. Quote Link to comment https://forums.phpfreaks.com/topic/205160-sql-syntax-error-i-cant-fix-it/#findComment-1073884 Share on other sites More sharing options...
Mchl Posted June 18, 2010 Share Posted June 18, 2010 Does anyone else smell bad design? Quote Link to comment https://forums.phpfreaks.com/topic/205160-sql-syntax-error-i-cant-fix-it/#findComment-1073930 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.