09.php

<html>
<head>
    <title>在线订单表保存至文件中</title>
</head>
<body>
    <form action="10.php" method="post">
        <h2>在线订单表保存至文件中</h2>
        <table bgcolor="#cccccc">
            <tr>
                <td>客户姓名:</td>
                <td><input type="text" name="name" size="10"></td>
            </tr>
            <tr>
                <td>联系方式</td>
                <td><input type="text" name="phone" size="15"></td>
            </tr>
            <tr>
                <td>备注内容:</td>
                <td><input type="text" name="note" size="30"></td>
            </tr>
            <tr>
                <td><input type="submit" value="提交"></td>
                <td><input type="reset" value="重置"></td>
            </tr>
        </table>
    </form>
    <span><a href="11.php">查看文件</a></span>
</body>
</html>

10.php

<?php
//保存文件
if($_POST)
{
    $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
    $name = trim($_POST['name']);
    $phone = trim($_POST['phone']);
    $note = trim($_POST['note']);
    $date = date("Y-m-d H:i:s");

    $string = "客人{$name},您的联系方式是{$phone},特殊要求包括{$note},时间:{$date} \n";

    $fp = fopen("$DOCUMENT_ROOT/booked.txt",'ab');
    if(fwrite($fp,$string,strlen($string)))
    {
        echo "订房信息已经保存.<br>";
    }
    else
    {
        echo "保存出错.<br>";
    }

    fclose($fp);
}


11.php

<?php
//读取文件
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

@$fp = fopen("$DOCUMENT_ROOT/booked.txt",'rb');

if($fp)
{
    while(!feof($fp))
    {
        $string = fgets($fp,2048);
        echo $string."<br>";
    }

}
else
{
    echo "没有订房信息.<br>";
}

fclose($fp);