PHP syntax error “unexpected $end”

ぃ、小莉子 提交于 2019-11-27 09:43:54
$result = mysql_query($sql, $connection) or die(mysql_error());
if ($result) {
    $msg = "<p>" .$_POST[table_name]." has been created!</p>";
}

you missing a } in your last if statement, and your for loop is missing a } too

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 .=",";
    }
} 

This error message means that a control structure block isn’t closed properly. In your case the closing } of some of your control structures like the for loop or the last if are missing.

You should use proper indentation and an editor that highlights bracket pairs to have a visual aid to avoid such errors.

You must close the for expression block:

for ($i = 0; $i < count($_POST[field_name]); $i++) {
    $sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
    // ...
}

Your for loop is not terminated. You are missing a }

for ($i = 0; $i < count($_POST[field_name]); $i++) {
  $sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
}

And as pointed by others there is also a missing } for the last if statement:

if ($result) {
  $msg = "< p>" .$_POST[table_name]." has been created!< /p>";
}

  in your php.ini (php configuration) change :

short_open_tag = Off


you opened php tag shortly at line 1
just find and replace all <? with <?php

Stylistic tip: Use HEREDOCs to assign blocks of text to a variable, instead of the hideous multi-line-with-tons-of-escaping-backslashes constructs you're using. They're far easier to read and less error prone if/when you happen to forget a \ somewhere and break the script with a parse error.

I just solved this error, after checking my code, I had no open tags/braces.
For me, I got this error when moving to a amazon server.
It turns out I needed to enable short_open_tag = On in my php.ini.
This solved this error for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!