为什么这是不必要的“>”在浏览器中显示此PHP文档时显示的字符?

时间:2010-05-19 14:06:16

标签: php

此页面从URL的$ _GET获取资产ID,并在查询mysql数据库后显示有关资产的一些信息。

当我在浏览器中查看该页面时,有一个不需要的“>”页面中的字符,我不明白为什么。

我评论它出现的地方。它出现在<表>之后创建标签。 <表>标签最初是在PHP脚本部分之外,但我把它扔进去看看它是否有所作为。它没。谢谢大家。

我在Firefox中查看该页面。 Web服务器正在我的笔记本电脑上的Ubuntu Server 10.04虚拟机上运行。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Wagman IT Asset</title>
</head>

<body>
    <div id="page">
                <div id="header">
                  <img src="images/logo.png" />
                </div>

                </div>

                <div id="content">
                    <div id="container">

                        <div id="main">
                        <div id="menu">
                            <ul>
                                <table width="100%" border="0">
                                <tr>
                                <td><li><a href="index.php">Search Assets</a></li></td>
                                <td><li><a href="browse.php">Browse Assets</a></li></td>
                                <td><li><a href="add_asset.php">Add Asset</a></li></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                </tr>
                                </table>
                          </ul>
                        </div>
                        <div id="text">
                        <ul>
                        <li>
                        <h1>View Asset</h1>
                        </li>
                        </ul>
//UNWANTED > CHARACTER APPEARS HERE
<?php

echo "<table width='100%' border='0' cellpadding='2'>";
//make database connect
mysql_connect("localhost", "asset_db", "asset_db") or die(mysql_error());
mysql_select_db("asset_db") or die(mysql_error());

//get asset
$id = $_GET["id"];
//get type of asset
$sql = "SELECT asset.type
From asset
WHERE asset.id = $id";
$result = mysql_query($sql)
or die(mysql_error());
$row = mysql_fetch_assoc($result);
$type = $row['type'];

switch ($type){
case "Server":
$sql = "
SELECT asset.id
,asset.company
,asset.location
,asset.purchase_date
,asset.purchase_order
,asset.value
,asset.type
,asset.notes
,server.manufacturer
,server.model
,server.serial_number
,server.esc
,server.user
,server.prev_user
,server.warranty
FROM asset
LEFT JOIN server
    ON server.id = asset.id
WHERE asset.id = $id
";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Asset ID:</td><td>";
    $id = $row['id'];
    setcookie('id', $id);
    echo "$id</td></tr>";
    echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";
    $company = $row['company'];
    setcookie('company', $company);
    echo "$company</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Location:</td><td>";
    $company = $row['location'];
    setcookie('location', $location);
    echo "$location</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Date:</td><td>";
    $purchase_date = $row['purchase_date'];
    setcookie('purchase_date', $purchase_date);
    echo "$purchase_date</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Order:</td><td>";
    $purchase_order = $row['purchase_order'];
    setcookie('purchase_order', $purchase_order);
    echo "$purchase_order</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Value:</td><td>";
    $value = $row['value'];
    setcookie('value', $value);
    echo "$value</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Type:</td><td>";
    $type = $row['type'];
    setcookie('type', $type);
    echo "$type</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Notes:</td><td>";
    $notes = $row['notes'];
    setcookie('notes', $notes);
    echo "$notes</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Manufacturer:</td><td>";
    $manufacturer = $row['manufacturer'];
    setcookie('manufacturer', $manufacturer);
    echo "$manufacturer</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Model / Description:</td><td>";
    $model = $row['model'];
    setcookie('model', $model);
    echo "$model</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Serial Number / Service Tag:</td><td>";
    $serial_number = $row['serial_number'];
    setcookie('serial_number', $serial_number);
    echo "$serial_number</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Express Service Code:</td><td>";
    $escy = $row['esc'];
    setcookie('esc', $esc);
    echo "$esc</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>User:</td><td>";
    $user = $row['user'];
    setcookie('user', $user);
    echo "$user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Previous User:</td><td>";
    $prev_user = $row['prev_user'];
    setcookie('prev_user', $prev_user);
    echo "$prev_user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Warranty:</td><td>";
    $warranty = $row['warranty'];
    setcookie('warranty', $warranty);
    echo "$warranty</td></tr></table>";
}

break;


case "Laptop":
$sql = "
SELECT asset.id
,asset.company
,asset.location
,asset.purchase_date
,asset.purchase_order
,asset.value
,asset.type
,asset.notes
,laptop.manufacturer
,laptop.model
,laptop.serial_number
,laptop.esc
,laptop.user
,laptop.prev_user
,laptop.warranty
FROM asset
LEFT JOIN laptop
    ON laptop.id = asset.id
WHERE asset.id = $id
";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Asset ID:</td><td>";
    $id = $row['id'];
    setcookie('id', $id);
    echo "$id</td></tr>";
    echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";
    $company = $row['company'];
    setcookie('company', $company);
    echo "$company</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Location:</td><td>";
    $company = $row['location'];
    setcookie('location', $location);
    echo "$location</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Date:</td><td>";
    $purchase_date = $row['purchase_date'];
    setcookie('purchase_date', $purchase_date);
    echo "$purchase_date</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Order:</td><td>";
    $purchase_order = $row['purchase_order'];
    setcookie('purchase_order', $purchase_order);
    echo "$purchase_order</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Value:</td><td>";
    $value = $row['value'];
    setcookie('value', $value);
    echo "$value</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Type:</td><td>";
    $type = $row['type'];
    setcookie('type', $type);
    echo "$type</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Notes:</td><td>";
    $notes = $row['notes'];
    setcookie('notes', $notes);
    echo "$notes</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Manufacturer:</td><td>";
    $manufacturer = $row['manufacturer'];
    setcookie('manufacturer', $manufacturer);
    echo "$manufacturer</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Model / Description:</td><td>";
    $model = $row['model'];
    setcookie('model', $model);
    echo "$model</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Serial Number / Service Tag:</td><td>";
    $serial_number = $row['serial_number'];
    setcookie('serial_number', $serial_number);
    echo "$serial_number</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Express Service Code:</td><td>";
    $escy = $row['esc'];
    setcookie('esc', $esc);
    echo "$esc</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>User:</td><td>";
    $user = $row['user'];
    setcookie('user', $user);
    echo "$user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Previous User:</td><td>";
    $prev_user = $row['prev_user'];
    setcookie('prev_user', $prev_user);
    echo "$prev_user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Warranty:</td><td>";
    $warranty = $row['warranty'];
    setcookie('warranty', $warranty);
    echo "$warranty</td></tr></table>";
}

        break;  
case "Desktop":
$sql = "
SELECT asset.id
,asset.company
,asset.location
,asset.purchase_date
,asset.purchase_order
,asset.value
,asset.type
,asset.notes
,desktop.manufacturer
,desktop.model
,desktop.serial_number
,desktop.esc
,desktop.user
,desktop.prev_user
,desktop.warranty
FROM asset
LEFT JOIN desktop
    ON desktop.id = asset.id
WHERE asset.id = $id
";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Asset ID:</td><td>";
    $id = $row['id'];
    setcookie('id', $id);
    echo "$id</td></tr>";
    echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";
    $company = $row['company'];
    setcookie('company', $company);
    echo "$company</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Location:</td><td>";
    $company = $row['location'];
    setcookie('location', $location);
    echo "$location</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Date:</td><td>";
    $purchase_date = $row['purchase_date'];
    setcookie('purchase_date', $purchase_date);
    echo "$purchase_date</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Purchase Order:</td><td>";
    $purchase_order = $row['purchase_order'];
    setcookie('purchase_order', $purchase_order);
    echo "$purchase_order</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Value:</td><td>";
    $value = $row['value'];
    setcookie('value', $value);
    echo "$value</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Type:</td><td>";
    $type = $row['type'];
    setcookie('type', $type);
    echo "$type</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Notes:</td><td>";
    $notes = $row['notes'];
    setcookie('notes', $notes);
    echo "$notes</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Manufacturer:</td><td>";
    $manufacturer = $row['manufacturer'];
    setcookie('manufacturer', $manufacturer);
    echo "$manufacturer</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Model / Description:</td><td>";
    $model = $row['model'];
    setcookie('model', $model);
    echo "$model</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Serial Number / Service Tag:</td><td>";
    $serial_number = $row['serial_number'];
    setcookie('serial_number', $serial_number);
    echo "$serial_number</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Express Service Code:</td><td>";
    $escy = $row['esc'];
    setcookie('esc', $esc);
    echo "$esc</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>User:</td><td>";
    $user = $row['user'];
    setcookie('user', $user);
    echo "$user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Previous User:</td><td>";
    $prev_user = $row['prev_user'];
    setcookie('prev_user', $prev_user);
    echo "$prev_user</td></tr>";
    echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Warranty:</td><td>";
    $warranty = $row['warranty'];
    setcookie('warranty', $warranty);
    echo "$warranty</td></tr></table>";
}
        break;  
}

?>

                        </div>

                        </div>
                </div>
                <div class="clear"></div>
                <div id="footer" align="center">
                    <p>&nbsp;</p>
                </div>
                </div>
                <div id="tagline">
                Wagman Construction - Bridging Generations since 1902
                </div>


</body>
</html>

4 个答案:

答案 0 :(得分:4)

echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>**>**<td>Company:</td><td>";

答案 1 :(得分:4)

看这里

echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";
    $company = $row['company'];

下次将表格边框设置为1,你会发现这个更快

答案 2 :(得分:3)

在第88行,你有:

echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";

它应该是:

echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";

您在第178行和第266行重复了错误

答案 3 :(得分:2)

嘿,在第5行的第一个While循环中你有:

echo "<tr<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>><td>Company:</td><td>";

如您所见,缺少tr标签&gt;符号(&gt;,这里是您在浏览器中显示的&gt;。只需将代码更正为:

echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>Company:</td><td>";

一切都应该没问题。)

的Ladislav