从 merch.txt 读取数据的 CGI 可以工作,但我怎样才能把它放在一个表中?
HTML 文件:
<form action="/cgi-bin/asst5/data.cgi" method="post">
<table border="2" cellspacing="5" cellpadding="5">
<tr>
<td align="center">SKU: </td>
<td><input type="text" name="code" size="15"></td>
</tr>
<tr>
<td align="center">Name: </td>
<td><input type="text" name="customer" size="15"></td>
</tr>
</table>
</form>
Data.CGI,其中数据在 HTML 中输入后被接受
my $sku = param('code');
my $cust = param('customer');
print <<HERE;
<HTML>
<BODY>
SKU: $sku<br>
Name: $cust<br>
HERE
open (ORDERS, ">>merch.txt") or die "File error, $!";
print ORDERS "$sku|$cust\n";
close ORDERS;
Read.CGI 这是从 merch.txt 读取内容的 CGI 文件
open ( ORDERS, "merch.txt" ) or die "Error opening file, $!";
my @orders = <ORDERS>;
close ORDERS;
print <<here;
<HTML>
<BODY>
here
for (my $i = 0; $i < @orders; $i++ ) {
print "<td><pre>", CGI::escapeHTML($orders[$i])."<br>\n", "</pre></td>\n";
}
print <<MORE;
</BODY>
</HTML>
MORE