php - 为图书馆学校制作一个 fwrite 联系人 PHP
问题描述
我试图用 PHP 制作联系人簿,这个网站是我学校的,我是初中老师,但我不能制作 PHP 代码/对不起
索引.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>
这里.html
<head>
<title>Thank you!</title>
</head>
<body>
Data Telah di Input.<br>
CEk Disini <a href="data.html" >Data</a>
</body>
文件.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>
<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>
解决方案
删除echo
并table
使用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;
}
推荐阅读
- c# - 假设在编写扩展方法时实现了 ToString()
- php - 加载图像php后预加载器继续加载
- python - Python:带有 numpy 数组的属性设置器
- properties - 在系统重新启动时,为什么 Hashicorp 领事属性会更改?
- c# - 动作过滤器属性中的调用配置设置
- android - 键盘显示在 ExpandableListView android 之上
- python - 将 python 脚本(具有 __name__ == '__main__')转换为包/库
- javascript - 如何开始使用 Vuejs/Nuxtjs 应用程序中的 @jsplumb/browser-ui?
- python - 如何获取包含给定列表中句子中的单词的字典作为键和该给定列表中出现的列表
- angular - 如果表只有一行,则运行函数