【发布时间】:2017-02-22 16:18:50
【问题描述】:
下面标注的表单提供了一系列选项供您使用选择表单进行选择。当从 $_POST 数组中检索到值时,尽管传递了正确的 id,但 season 的值似乎只是表单中的最后一个值。
我已经检查了我的代码,据我所知,联赛没有在其他任何地方更新。
我确定我遗漏了一些明显但无法弄清楚的东西!
<form method = 'post' action = 'index.php?choice=matcht&stage=1'><table width = '50%' border = '1'><thead><tr>
<th>Select</th>
<th>League</th>
<th>Season</th>
</tr></thead>
<tr><td><input type = 'radio' name = 'id' value = '1' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '12' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '25' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '13' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '49' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '14' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '73' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '15' readonly></td>
</tr>
<tr><td><input type = 'radio' name = 'id' value = '97' ></td>
<td><input type = 'text' name = 'league' value = 'MLB21' readonly></td>
<td><input type = 'text' name = 'season' value = '16' readonly></td>
</tr>
<tr><td colspan = '3' align = 'center'><input type = 'submit' name = 'go' value = 'GO'></td></tr>
</table>
</form>
这是生成 HTML 的 PHP:
$sql='SELECT `TeamID`, `League`,`Season` FROM teams WHERE `FranchiseID` = 0 GROUP BY `League`,`Season` ORDER BY `League` ASC ,`Season` ASC ';
$unmatched = $db2->get_results($sql);
if ($db2->num_rows>0) {
echo "<form method = 'post' action = 'index.php?choice=matcht&stage=1'>";
echo "<table width = '50%' border = '1'>";
echo "<thead><tr>\n";
echo "<th>Select</th>\n";
echo "<th>League</th>\n";
echo "<th>Season</th>\n";
echo "</tr></thead>\n";
foreach ( $unmatched as $unmatch )
{
// Access data using object syntax
echo "<tr>";
echo "<td><input type = 'radio' name = 'id' value = '$unmatch->TeamID' ></td>\n";
echo "<td><input type = 'text' name = 'league' value = '".$unmatch->League."' readonly></td>\n";
echo "<td><input type = 'text' name = 'season' value = '".$unmatch->Season."' ></td>\n";
echo "</tr>\n";
}
echo "<tr><td colspan = '3' align = 'center'><input type = 'submit' name = 'go' value = 'GO'></td></tr>\n";
echo "</table>\n";
echo "</form>\n";
【问题讨论】: