如何在 PHP 中创建一个表单,用户输入的结果将在表格中生成?当我测试页面时,我只得到表、键和结果(值)字段的开头,但没有值!
这是我的代码(我将字段数缩短为两个,因为表单可能很长:
订单:
<?php
foreach ($_POST as $key => $entry)
{
$totalfields++;
echo "<tr>\n";
echo "<td>" . $key . "</td>";
if (is_array ($entry)) {
$count = count($entry);
echo "<td>";
for ($i=0; $i<$count; $i++){
echo $entry[$i] . "<br />";
}
echo "</td>";
} else
{
echo "<td>$entry</td>";
}
echo "<tr>\n";
}
?>
<form method="post" action="address to the results form page">
<label for="fname">First Name:</label>
<input type="text" name="fname" id="fname"/><br/>
<br/>
<label for="lname">Last Name:</label>
<input type="text" name="lname" id="lname"/><br/>
<br/>
<p><input type="submit" value="Submit"/></p>
</form>
结果表格页面:
<div id="results table">
<table border='1'>
<tr>
<th>
Field
</th>
<th>
Results
</th>
</tr>
</table>
</div>