【问题标题】:PHP Error Parse error: syntax error, unexpected $endPHP 错误解析错误:语法错误,意外 $end
【发布时间】:2012-08-15 22:03:39
【问题描述】:

您收到错误解析错误:语法错误,第 124 行 /home/crafru/public_html/test/damienform.php 中的意外 $end

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-gb" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
.table-style1 {
    border: 1px solid #000000;
    width: 39%;
    height: 197px;
}
.table-style2 {
    border: 1px solid #000000;
    text-align: center;
    font-weight: bold;
    height: 25px;
}
.table-style3 {
    border: 1px solid #000000;
    text-align: center;
    font-weight: bold;
    width: 221px;
    height: 25px;
}
.table-style4 {
    border: 1px solid #000000;
    width: 221px;
    height: 25px;
}
.table-style5 {
    height: 25px;
    border: 1px solid #000000;
}
</style>
</head>
<body style="font-family: Arial, Helvetica, sans-serif; background-color: #EBF4FB">
<?php
    $submitrunnertime= $_POST['submitrunnertime'];
    $RunnerID= $_POST['RunnerID'];
    $EventID= $_POST['EventID'];
    $Date= $_POST['Date'];
    $Time= $_POST['Time'];
    $Position= $_POST['Position'];
    $CategoryID= $_POST['CategoryID'];
    $AgeGrade= $_POST['AgeGrade'];
    $PB= $_POST['PB'];
    $submitrunnertime= $_POST['submitrunnertime'];
    $Test = "pass";

    $host= 'localhost';
    $user= '****';  
    $password= '****';
    $database= '****';

/**
    Function: connect to a database.
    $host = hostname to connect to e.g. 'localhost'
    $id = username identity, e.g. 'ta589'
    $pwd = user password, e.g. 'twiggy9'
    $db = database to use, e.g. 'ta589'
    Returns the database connection.
**/

function connect_db($host, $user, $password, $database) {
    $connection = @mysql_connect($host, $id, $pwd)
        or die('connection problem:' . mysql_error());
    mysql_select_db($db)
        or die('db selection problem:' . mysql_error());
    return $connection;
?>

<table class="table-style1" cellpadding="0" cellspacing="0">
    <tr>
        <td class="table-style3">Feild</td>
        <td class="table-style2">Value</td>
    </tr>
    <tr>
        <td class="table-style4">Runner ID </td>
        <td class="table-style5"><?=$RunnerID?></td>
    </tr>
    <tr>
        <td class="table-style4">Event ID </td>
        <td class="table-style5"><?=$EventID?></td>
    </tr>
    <tr>
        <td class="table-style4">Date </td>
        <td class="table-style5"><?=$Date?></td>
    </tr>
    <tr>
        <td class="table-style4">Time </td>
        <td class="table-style5"><?=$Time?></td>
    </tr>
    <tr>
        <td class="table-style4">Position </td>
        <td class="table-style5"><?=$Position?></td>
    </tr>
    <tr>
        <td class="table-style4">Category ID </td>
        <td class="table-style5"><?=$CategoryID?></td>
    </tr>
    <tr>
        <td class="table-style4">Age Grade </td>
        <td class="table-style5"><?=$AgeGrade?></td>
    </tr>
    <tr>
        <td class="table-style4">PB </td>
        <td class="table-style5"><?=$PB?></td>
    </tr>
    <tr>
        <td class="table-style4">submitrunnertime </td>
        <td class="table-style5"><?=$submitrunnertime?></td>
    </tr>
    <tr>
        <td class="table-style4">Test - Remove this</td>
        <td class="table-style5"><?=$Test?></td>
    </tr>
</table>
</body>
</html>

一直在看这个,看不到任何丢失的结束位。我错过了什么?

【问题讨论】:

  • 这可能无助于回答您的问题,但您应该停止使用mysql_* 函数。它们正在被弃用。请改用PDO(PHP 5.1 起支持)或mysqli(PHP 4.1 起支持)。如果您不确定要使用哪一个,read this article.
  • 这是一个非常简单的错误,我的建议是使用 ZendStudio 或 Netbeans 之类的 IDE .. 你很容易发现这样的错误。发生错误是因为您的connect_db() 中缺少}
  • @Baba 实际上,在这种情况下,NetBeans 并没有指出错误(至少对我而言);格式有点偏离,但没有红色下划线或其他错误指示​​。
  • 你用的是什么版本@Matt
  • @Baba 无视;错误指示器位于最后一行。

标签: php syntax parse-error


【解决方案1】:

你的函数缺少一个结束的'stache。

function connect_db($host, $user, $password, $database) {
    $connection = @mysql_connect($host, $id, $pwd)
      or die('connection problem:' . mysql_error());
    mysql_select_db($db)
      or die('db selection problem:' . mysql_error());
    return $connection;
} //<--THAT ONE

?>

【讨论】:

    猜你喜欢
    • 2014-08-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多