vieworder.php
<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
@ $fp= fopen("$DOCUMENT_ROOT/orders/orders.txt",'rb');

if(!$fp)
{
echo "<p><strong>No orders pending.Please try again later.</strong></p>";
exit;
}
while(!feof($fp))
{
$order= fgets($fp,999);
echo $order. '<br />';
}
?>
<p>Go to <a href ="vieworders2.php">ViewOrders2</a></p>
</body>
</html>
能够成功运行:如下:
Bob's Auto Parts
Customer Orders
22:32,16th May 2011 2 tires 4 oil 6 spark plugs $264.00 22 short St,Smalltown
22:33,16th May 2011 2 tires 40 oil 6 spark plugs $624.00 22 short St,Smalltown 
可是到了vieworder2.php
<?php
$DUCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
$orders = file("$DOCUMENT_ROOT/orders/orders.txt");

$number_of_orders = count($orders);

if($number_of_orders == 0){
echo "<p><strong>No Orders pending.
Please try again later.</strong></p>";
}
echo "<table border =\"1\">\n";
echo "<tr><th bgcolor =\"#ccccff\">Order Date</th>
<th bgcolor =\"#ccccff\">Tires</th>
<th bgcolor =\"#ccccff\">Oil</th>
<th bgcolor =\"#ccccff\">Spark Plugs</th>
<th bgcolor =\"#ccccff\">Total</th>
<th bgcolor =\"#ccccff\">Address</th>
</tr>";
for($i=0; $i<number_of_orders;$i++)
{
$line = explore("\t",$orders[$i]);
$line[1] = intval($line[1]);
$line[2] = intval($line[2]);
$line[3] = intval($line[3]);

echo "<tr>
<td>".$line[0]."</td>
<td align=\"right\">".$line[1]."</td>
<td align=\"right\">".$line[2]."</td>
<td align=\"right\">".$line[3]."</td>
<td align=\"right\">".$line[4]."</td>
<td>".$line[5]."</td>
</tr>";
}
echo "</table>";
?>
</body>
</html>
却始终找不到文件呢?
Bob's Auto Parts
Customer OrdersWarning: file(/orders/orders.txt) [function.file]: failed to open stream: No such file or directory in F:\AppServ\www\test\vieworders2.php on line 17

解决方案 »

  1.   

    晕不是在你另一个帐号发的帖子中回答你了啊。。
    vieworder2.php中定义的变量名是$DUCUMENT_ROOT,第17行使用这个变量时写的是:
    $orders = file("$DOCUMENT_ROOT/orders/orders.txt");名称不一样,看到了吗,有木有??
      

  2.   

    怎么提高这种东西的识别能力啊,有没有像VC++,assisant X,这种辅助系统啊,我用的是记事本,太简单了
      

  3.   

    Dreamweaver、PHPEclipse等是很好的IDE。不过IDE起的是代码高亮、语法提示的作用,大部分的代码错误还是要根据运行时的错误提示来排查。
    http://www.ibm.com/developerworks/cn/opensource/os-php-ide/
      

  4.   

    你的错误在于变量自命名的拼写错误(我看半天也没留意,还是马甲细心,鼓掌!),php本身不认为是错误
    就算ide也查不到,如果你习惯命名都是有语义的(这个习惯好),可以用单词拼写检查做这个事另外就是用debug跟踪
    http://bbs.phpchina.com/viewthread.php?tid=209365
    xdebug的介绍,不过弄熟也要一定时间
    官网 http://www.xdebug.org/我现在还是离不开逐级回溯echo...-_-!
      

  5.   

    其实php报错功能已经非常不错了,几乎出现错误就能明白大致哪里错误了,不过听说zenddebug挺牛的,不过就是zendstatio有点大,你可以试一试