解析错误:语法错误,在128行的文件中意外的$end。

时间:2021-10-20 22:43:15

Hi So this is the code: Its a page to display my available tables in the database in a drop-down, then display the results in the table. The actual code to do so (in the middle) works perfectly on its own, but when I try to add my template around it I get errors...

这是代码:它的一个页面在下拉菜单中显示我的可用表,然后在表中显示结果。实际的代码(在中间)是完全独立工作的,但是当我尝试在它周围添加模板时,我就会出错……

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" >
<meta name="description" content="" >
<meta http-equiv="content-type" content="text/html; charset=utf-8" >
<title>SNYSB Archive</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" >
<!-- Location of javascript. -->
<script language="javascript" type="text/javascript" src="swfobject.js" ></script>
</head>
    <div id="wrapper">
    <div id="header">
    <!-- KEEP THIS BIT [ITS FORMATTING] --> 
    </div>
    <!-- end #header -->
    <div id="menu">
            <ul>
            <li><a href="Hpage.php">Home</a></li>
            <li><a href="Register.php">Register</a></li>
        </ul>
    </div>
    <!-- end #menu -->
    <div id="page">
    <div id="page-bgtop">
    <div id="page-bgbtm">
    <div id="content">
            <div class="post">
            <div class="post-bgtop">
            <div class="post-bgbtm">
<h1 class="title">PUT HEADING HERE!</h1>
                <div class="entry">
                    <p class="Body">
<?php
$dbname = 'snysbarchive';
$conn= mysql_connect('localhost', 'root', 'usbw');
if (!$conn) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
if (mysql_select_db($dbname, $conn))
{
?>
    <form method="post" action="new 2.php">
    <select name="tables">
    <?php
    while ($row = mysql_fetch_row($result)) {
    ?>    
    <?php
        echo '<option value="'.$row[0].'">'.$row[0].'</option>';
    }
    ?>
    </select>
    <input type="submit" value="Show">
</form>
<?php
//mysql_free_result($result);
if (isset($_POST) && isset($_POST['tables']))
{
    $tbl=$_POST['tables'];
    //echo $_POST['tables']."<br />";
    $query="SELECT * from $tbl";
    $res=mysql_query($query);
    echo $query;
    if ($res)
    {
    ?>
    <table border="1">
    <?php
        while ( $row = mysql_fetch_array($res))
        {
            echo "<tr>";
            echo "<td>".$row[0]."</td>";
            echo "<td>".$row[1]."</td>";
            echo "<td>".$row[2]."</td>";
            echo "<td>".$row[3]."</td>";        
            echo "</tr>";
        } ?>
    </table>
    <?php
    }
}
?>
</div>
</div>
            </div>
            </div>

        <div style="clear: both;">&nbsp;</div>
        </div>
        <!-- end #content -->
        <div id="sidebar">
            <ul>
                <li>
                    <h2>Welcome!</h2>
                    <p>Welcome to SNYSBs archive!
                       </p>
                </li>
                <li>
                    <h2>SNYSB</h2>
                    <p>
            <a href="Contact.php">Contact Us!</a>
                    </p>
                </li>
            </ul>
        </div>
        <!-- end #sidebar -->
        <div style="clear: both;">&nbsp;</div>
    </div>
    </div>
    </div>
    <!-- end #page -->
    <div id="footer">
        <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
    </div>
    <!-- end #footer -->
</div>
</body>
</html>

It keeps saying unexpected end but I am not sure how to fix it?

它一直在说意想不到的结局,但我不知道该如何解决它?

Error Message:Parse error: syntax error, unexpected $end in file on line 128

Thanks

谢谢

6 个解决方案

#1


-1  

You have not selected your database with correct braces around the function.

您没有在函数周围使用正确的括号来选择数据库。

#2


12  

This may also occur when mixing short and normal open tags when the server does not support short-open-tags (<? instead of <?php), even though this wasn't the case in your code.

当服务器不支持短开标签(

<?php

$showHeader = true;

if ($showHeader) {
?>
<h1>Hello, World!</h1>
<?
}
?>

Note that the closing bracket will not be registered if the server doesn't support the <? open tag.

注意,如果服务器不支持

#3


11  

Line 50: if (mysql_select_db($dbname, $conn)) has an opening bracket and not a closing one.

第50行:if (mysql_select_db($dbname, $conn))有一个开头括号,而不是关闭括号。

#4


3  

You may need to change <? to <?php

您可能需要更改

#5


0  

you forget to close this block with a } :

您忘记关闭这个块的一个}:

if (mysql_select_db($dbname, $conn))
{
?>

Try this code :

试试这段代码:

<?php
$dbname = 'snysbarchive';
$conn= mysql_connect('localhost', 'root', 'usbw');
if (!$conn) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
if (mysql_select_db($dbname, $conn))
{
?>
    <form method="post" action="new 2.php">
    <select name="tables">
    <?php
    while ($row = mysql_fetch_row($result)) {
        echo '<option value="'.$row[0].'">'.$row[0].'</option>';
    }
    ?>
    </select>
    <input type="submit" value="Show">
    </form>
<?php
}

//mysql_free_result($result);
if (isset($_POST) && isset($_POST['tables']))
{
    $tbl=$_POST['tables'];
    //echo $_POST['tables']."<br />";
    $query="SELECT * from $tbl";
    $res=mysql_query($query);
    echo $query;
    if ($res)
    {
    ?>
    <table border="1">
    <?php
        while ( $row = mysql_fetch_array($res))
        {
            echo "<tr>";
            echo "<td>".$row[0]."</td>";
            echo "<td>".$row[1]."</td>";
            echo "<td>".$row[2]."</td>";
            echo "<td>".$row[3]."</td>";        
            echo "</tr>";
        } 
    ?>
    </table>
    <?php
    }
}
?>

#6


0  

You have missed a '}' so following if block is not closed.

您已经错过了一个“}”,如果块没有关闭,那么就会出现以下情况。

if (mysql_select_db($dbname, $conn))
{ 

By adding a } in Line #91 your code will be worked.

通过在第91行添加一个},您的代码将被工作。

But always try to write much cleaner code by following best practices.

但是,总是尝试通过遵循最佳实践来编写更清晰的代码。

#1


-1  

You have not selected your database with correct braces around the function.

您没有在函数周围使用正确的括号来选择数据库。

#2


12  

This may also occur when mixing short and normal open tags when the server does not support short-open-tags (<? instead of <?php), even though this wasn't the case in your code.

当服务器不支持短开标签(

<?php

$showHeader = true;

if ($showHeader) {
?>
<h1>Hello, World!</h1>
<?
}
?>

Note that the closing bracket will not be registered if the server doesn't support the <? open tag.

注意,如果服务器不支持

#3


11  

Line 50: if (mysql_select_db($dbname, $conn)) has an opening bracket and not a closing one.

第50行:if (mysql_select_db($dbname, $conn))有一个开头括号,而不是关闭括号。

#4


3  

You may need to change <? to <?php

您可能需要更改

#5


0  

you forget to close this block with a } :

您忘记关闭这个块的一个}:

if (mysql_select_db($dbname, $conn))
{
?>

Try this code :

试试这段代码:

<?php
$dbname = 'snysbarchive';
$conn= mysql_connect('localhost', 'root', 'usbw');
if (!$conn) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}
if (mysql_select_db($dbname, $conn))
{
?>
    <form method="post" action="new 2.php">
    <select name="tables">
    <?php
    while ($row = mysql_fetch_row($result)) {
        echo '<option value="'.$row[0].'">'.$row[0].'</option>';
    }
    ?>
    </select>
    <input type="submit" value="Show">
    </form>
<?php
}

//mysql_free_result($result);
if (isset($_POST) && isset($_POST['tables']))
{
    $tbl=$_POST['tables'];
    //echo $_POST['tables']."<br />";
    $query="SELECT * from $tbl";
    $res=mysql_query($query);
    echo $query;
    if ($res)
    {
    ?>
    <table border="1">
    <?php
        while ( $row = mysql_fetch_array($res))
        {
            echo "<tr>";
            echo "<td>".$row[0]."</td>";
            echo "<td>".$row[1]."</td>";
            echo "<td>".$row[2]."</td>";
            echo "<td>".$row[3]."</td>";        
            echo "</tr>";
        } 
    ?>
    </table>
    <?php
    }
}
?>

#6


0  

You have missed a '}' so following if block is not closed.

您已经错过了一个“}”,如果块没有关闭,那么就会出现以下情况。

if (mysql_select_db($dbname, $conn))
{ 

By adding a } in Line #91 your code will be worked.

通过在第91行添加一个},您的代码将被工作。

But always try to write much cleaner code by following best practices.

但是,总是尝试通过遵循最佳实践来编写更清晰的代码。