Parse error: syntax error, unexpected '}'

2020-05-10 14:48发布

I got this error

Parse error: syntax error, unexpected '}' in C:\wamp\www\widget_corp\public
\create_subject.php on line 24

when I clicked on my "Creae Subject" button.

I have tried to fix it all day but really can't find what the problem is.

<?php require_once ("../includes/session.php"); ?>
<?php require_once ("../includes/db_connection.php"); ?>
<?php require_once ("../includes/functions.php"); ?>
<?php require_once ("../includes/validation_function.php"); ?>

<?php
if (isset($_POST['submit'])) {
    // Process the form

    $menu_name = mysql_prep($_POST["menu_name"]);
    $position =  (int) $_POST["position"];
    $visible = (int) $_POST["visible"];

    // Validations
    $required_fields = array("menu_name", "position", "visible");
    validate_presences($required_fields);

    $fields_with_max_lengths = array("menu_name" => 30);
    validate_max_lengths($fields_with_max_lengths);

    if (!empty($errors)) {
        $_SESSION["errors"] = $errors;
        redirect_to("new_subject.php")
    } <-------- THIS IS ROW 24! ----------->

        $query  = "INSERT INTO subjects (";
        $query .= "  menu_name, position, visible";
        $query .= ") VALUES (";
        $query .= "  '{$menu_name}, {$position}, {$visible}";
        $query .= ")";
        $result = mysqli_query($connection, $query);

    if ($result) {
        // Success
        $_SESSION["message"] = "Subject created!";
        redirect_to("manage_content.php");
    } else {
        // Failure
        $_SESSION["message"] = "Subject creation failed";
        redirect_to("new_subject.php");
    }

} else {

  // This is probably a GET request
  redirect_to("new_subject.php");
}

?>

<!-- Close database connection -->
<?php if (isset($connection)) { mysqli_close($connection); } ?>

2条回答
淡お忘
2楼-- · 2020-05-10 15:34

you have missed semicolon in this line:

redirect_to("new_subject.php");

try this:

 if (!empty($errors)) {
        $_SESSION["errors"] = $errors;
        redirect_to("new_subject.php");
    } 
查看更多
Anthone
3楼-- · 2020-05-10 15:49

Missing semicolon on the line above the brace.

redirect_to("new_subject.php")

A lot of times you have to look at the line above the one given in the error to see what the problem is.

查看更多
登录 后发表回答