PHP syntax error “unexpected $end”

前端 未结 7 768
清酒与你
清酒与你 2020-12-02 01:52

I have 3 files 1) show_createtable.html 2) do_showfielddef.php 3) do_showtble.php

1) First file is for creating a new table for a data base, it is a fom with 2 input

相关标签:
7条回答
  • 2020-12-02 02:25

    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>";
    }

    0 讨论(0)
  • 2020-12-02 02:26

      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

    0 讨论(0)
  • 2020-12-02 02:27

    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.

    0 讨论(0)
  • 2020-12-02 02:28
    $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 .=",";
        }
    } 
    
    0 讨论(0)
  • 2020-12-02 02:28

    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.

    0 讨论(0)
  • 2020-12-02 02:28

    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.

    0 讨论(0)
提交回复
热议问题