Jump to content

SQL syntax error... I can't fix it :(


morocco-iceberg

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/205160-sql-syntax-error-i-cant-fix-it/
Share on other sites

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')";

Archived

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

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