解析错误:语法错误,意外'' [关闭]
Posted
技术标签:
【中文标题】解析错误:语法错误,意外\'\' [关闭]【英文标题】:Parse error: syntax error, unexpected '' [closed]解析错误:语法错误,意外'' [关闭] 【发布时间】:2014-04-02 08:12:42 【问题描述】:我收到了这个错误
Parse error: syntax error, unexpected '' in C:\wamp\www\widget_corp\public
\create_subject.php on line 24
当我点击“Creae Subject”按钮时。
我整天都在尝试修复它,但真的找不到问题所在。
<?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); ?>
【问题讨论】:
【参考方案1】:大括号上方的行中缺少分号。
redirect_to("new_subject.php")
很多时候,您必须查看错误中给出的行上方的行,以了解问题所在。
【讨论】:
【参考方案2】:你错过了这一行的分号:
redirect_to("new_subject.php");
试试这个:
if (!empty($errors))
$_SESSION["errors"] = $errors;
redirect_to("new_subject.php");
【讨论】:
以上是关于解析错误:语法错误,意外'' [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
解析错误:语法错误,意外的“公共”(T_PUBLIC)[关闭]
解析错误:语法错误,第 26 行 C:\xampp\htdocs\eifel\register.php 中的意外“”[关闭]