为图书馆学院创建一个 fwrite 联系人 PHP

Make a fwrite contact person PHP, for Library School

我正在尝试制作来自 PHP 的联系人簿, 这个网站是我学校的,我是一名初中老师 但我不能PHP代码/抱歉

Index.php

    <?php
    if(!empty($errorMessage)) 
    {
        echo("<p>There was an error with your form:</p>\n");
        echo("<ul>" . $errorMessage . "</ul>\n");
    } 
?>
<form action="file.php" method="post">
    <p>
        Name<br>
        <input type="text" name="aa" maxlength="50"  />
    </p>
    <p>
        Contact <br>
        <input type="text" name="ab" maxlength="50"  />
    </p>
    <p>
        Books<br>
        <input type="text" name="ac" maxlength="50"  />
    </p>            
    <input type="submit" name="formSubmit" value="Submit" />
</form>

here.html

<head>
 <title>Thank you!</title>
</head>

<body>
Data Telah di Input.<br>
CEk Disini <a href="data.html" >Data</a>


</body>

file.php

<?php
if($_POST['formSubmit'] == "Submit")
{
 $errorMessage = "";
 
 if(empty($_POST['aa']))
 {
  $errorMessage .= "<li>You forgot to enter a name</li>";
 }
 if(empty($_POST['ab']))
 {
  $errorMessage .= "<li>You forgot to enter a contact</li>";
 }
 if(empty($_POST['ac']))
 {
  $errorMessage .= "<li>You forgot to enter a book</li>";
 }
 
 $varaa = $_POST['aa'];
 $varab = $_POST['ab'];
 $varac = $_POST['ac'];

 
 if(empty($errorMessage)) 
 {
  $fs = fopen("data.html","ab");
  echo "<table > <tr><th>No</th> <th>Name</th> <th>Contact</th> <th>Books</th></tr>";
  fwrite($fs,"
  <tr>
       <td> ".$varaa. "</td>
   <td>" .$varab. "</td>
   <td>" .$varac. "</td>
  </tr>");
  echo "</table >";
  fclose($fs);
  
  header("Location: here.html");
  exit;
 }
}
?>

那么,为什么我得到这样的输出

  <tr>
       <td> Andreas</td>
   <td>64898722</td>
   <td>Test Book1</td>
  </tr>
  <tr>
       <td> Yuyun</td>
   <td>64898444</td>
   <td>Book4</td>
  </tr>

我想做这样的输出,但为什么我得到alawys失败我不知道如何做其他的php,抱歉。

我需要输出table,并在第一个table中添加数字。

<table>
 <tr><th>No</th> <th>Name</th> <th>Contact</th> <th>Books</th></tr>
  <tr>
   <td>1</td>
       <td> Andreas</td>
   <td>64898722</td>
   <td>Test Book1</td>
  </tr>
  <tr>
   <td>2</td>
       <td> Yuyun</td>
   <td>64898444</td>
   <td>Book4</td>
  </tr>
</table>

table 删除 echo 并使用 fwrite

if(empty($errorMessage)) 
{
    $fs = fopen("data.html","w");
    fwrite($fs, "<table > <tr><th>No</th> <th>Name</th> <th>Contact</th> <th>Books</th></tr>");
    fwrite($fs,"
    <tr>
         <td> ".$varaa. "</td>
        <td>" .$varab. "</td>
        <td>" .$varac. "</td>
    </tr>");
    fwrite($fs, "</table >");
    fclose($fs);

    header("Location: here.html");
    exit;
}