I think the problem is that the last time this for loop goes through:
PHP Code:
$sql = "CREATE TABLE $_POST[table_name] (";
for ($i = 0; $i < count($_POST[field_name]); $i++) {
$sql .= "$_POST[field_name][$i] $_POST[field_type][$i]";
if ($_POST[field_length][$i] != "") {
$sql .= " ($_POST[field_length][$i]), ";
} else {
$sql .= ", ";
}
}
... you're left with an extra comma at the end.
Do a check to see if you're at the last iteration of the loop. If you are, don't print the comma. Hopefully that helps.
Such as:
PHP Code:
$sql = "CREATE TABLE $_POST[table_name] (";
for ($i = 0; $i < count($_POST[field_name]); $i++) {
$sql .= "$_POST[field_name][$i] $_POST[field_type][$i]";
if ($_POST[field_length][$i] != "") {
$sql .= " ($_POST[field_length][$i]) ";
}
if ($i < $_POST[field_name]-1) {
$sql .= ", ";
}
}