我收到了这个错误
Parse error: syntax error, unexpected '}' in C:\wamp\www\widget_corp\public
\create_subject.php on line 24
当我点击我的“Creae主题”按钮时。
我试图整天解决这个问题,但实际上找不到问题所在。
<?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); } ?>
答案 0 :(得分:2)
在大括号上方的行上缺少分号。
redirect_to("new_subject.php")
很多时候你必须查看错误中给出的那一行以查看问题所在。
答案 1 :(得分:2)
你错过了这一行的分号:
redirect_to("new_subject.php");
试试这个:
if (!empty($errors)) {
$_SESSION["errors"] = $errors;
redirect_to("new_subject.php");
}