意外的文件结束;括号错位?

时间:2015-04-06 19:02:01

标签: php

我的代码出错了。

Error Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\phpcart5\products.php on line 41.

是括号错误还是因为while循环错误? 有人可以帮忙吗?

<?php  session_start();?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Shoping Cart </title>
    <!-- This page is for displaying the products -->
    </head>
    <body bgcolor="#000000">
    <div align="center">
    <h3 style="background-color:#FF0">Products</h3>
    <a style="color:#FFFF00; text-decoration:none" href="cart.php?action=none"><span style="margin-left:500px;">
    <img src="online/images/cart.png">Cart (<? echo count($_SESSION['cart']); ?>
    )</span></a>
    </br>
    <table border="0" bgcolor="#f6f6f6" cellpadding="0px" width="600px">
    <?php
    //Fetching the product details from database
    include("common/db.php");
    $result=mysql_query("select * from products");
    while($row=mysql_fetch_array($result)){
        ?>
        <tr>
        <!-- Displaying the shopping cart product -->
        <td>
        <img src="<?=$row['picture']?>" />
        </td>
        <td>
        <b><?=$row['name']?>
        </b><br/>
        <?=$row['description']?>
        <br/>
        Price:<big style="color:#455E5B">
        $<?=$row['price']?>
        </big><br/><br/>
        <a href="cart.php?id=<?=$row['serial']?>&action=add "><img src="images/add.png"/></a>
        </td>
        </tr>
        <tr>
        <td colspan="2">
        <hr size="1"/>
        </td>
    <? }?>
    </table>
    </div>
    </body>
    </html>

1 个答案:

答案 0 :(得分:0)

看起来你在脚本中使用了PHP短标签(<? /* PHP statement */ ?>)。如果php.ini文件中的任何short_open_tag设置设置为Off,则这些PHP标记会导致问题。

在PHP 5.4及更高版本中解决此问题的正确方法是什么?请改用<?php /* statement */ ?>

<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Shopping Cart</title>
    <!-- This page is for displaying the products -->
</head>
<body bgcolor="#000000">
<div align="center">
    <h3 style="background-color:#FF0">Products</h3>
    <a style="color:#FFFF00; text-decoration:none" href="cart.php?action=none"><span style="margin-left:500px;">
    <img src="online/images/cart.png">Cart (<?= count($_SESSION['cart']) ?>)</span></a>
    </br>

    <table border="0" bgcolor="#f6f6f6" cellpadding="0px" width="600px">
        <?php
        //Fetching the product details from database
        include("common/db.php");
        $result = mysql_query("select * from products");
        while ($row = mysql_fetch_array($result)){
        ?>
        <tr>
            <!-- Displaying the shopping cart product -->
            <td>
                <img src="<?= $row['picture'] ?>"/>
            </td>
            <td>
                <b><?= $row['name'] ?>
                </b><br/>
                <?= $row['description'] ?>
                <br/>
                Price:<span style="font-size:larger;color:#455E5B">
                    $<?= $row['price'] ?>
                </span><br/><br/>
                <a href="cart.php?id=<?= $row['serial'] ?>&action=add "><img src="images/add.png"/></a>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <hr size="1"/>
            </td>
            <?php } ?>
    </table>
</div>
</body>
</html>

如果由于某种原因,您无法使用PHP 5.4+(这是不好的;不再支持PHP 5.3),那么最简单的方法就是替换实例<?= $value ?><?php echo $value; ?>

。{
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Shopping Cart</title>
    <!-- This page is for displaying the products -->
</head>
<body bgcolor="#000000">
<div align="center">
    <h3 style="background-color:#FF0">Products</h3>
    <a style="color:#FFFF00; text-decoration:none" href="cart.php?action=none"><span style="margin-left:500px;">
        <img src="online/images/cart.png">Cart (<?php echo count($_SESSION['cart']);?>)</span></a>
    </br>

    <table border="0" bgcolor="#f6f6f6" cellpadding="0px" width="600px">
        <?php
        //Fetching the product details from database
        include("common/db.php");
        $result = mysql_query("select * from products");
        while ($row = mysql_fetch_array($result)){
        ?>
        <tr>
            <!-- Displaying the shopping cart product -->
            <td>
                <img src="<?php echo $row['picture'];?>"/>
            </td>
            <td>
                <b><?php echo $row['name'];?>
                </b><br/>
                <?php echo $row['description'];?>
                <br/>
                Price:<span style="font-size:larger;color:#455E5B">
                        $<?php echo $row['price'];?>
                    </span><br/><br/>
                <a href="cart.php?id=<?php echo $row['serial'];?>&action=add "><img src="images/add.png"/></a>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <hr size="1"/>
            </td>
            <?php } ?>
    </table>
</div>
</body>
</html>