-2

我有一个有 n 行的表。每行都有一个名称 [来自 Excel 文件] 和 2 组单选按钮。我应该如何在数据库中保存或插入选定的单选按钮?

我的数据库的结构是:id、name、vote_for_mayor、vote_for_vmayor

这是我的php代码。

echo '<form name="electionForm" action="submit.php" method="post" onreset="updateButCount(event);">
<button type="submit" value="Submit">Submit</button>

<table id="election" onclick="updateButCount(event);">
list($cols,) = $xlsx->dimension();
$var=0;
$var1=0;
foreach( $xlsx->rows() as $k => $r) {
    $var++;
    $var1++;
    <tr>
        <td>'.$k.'</td>
        <td>'.( (isset($r[0])) ? $r[0] : '&nbsp;' ).'</td>  //names
        <td><input type = "Radio" Name ="vote'.$var.'" value= "pacada"></td>
        <td><input type = "Radio" Name ="vote'.$var.'" value= "toledo"></td>
        <td><input type = "Radio" Name ="vote1'.$var1.'" value= "apostol"></td>
        <td><input type = "Radio" Name ="vote1'.$var1.'" value= "abdul"></td>
    </tr>
}
</table>
</form>';
4

1 回答 1

0

将 HTML 更改为:

    <td><input type = "Radio" Name ="vote['.$var.']" value= "pacada"></td>
    <td><input type = "Radio" Name ="vote['.$var.']" value= "toledo"></td>
    <td><input type = "Radio" Name ="vote1['.$var.']" value= "apostol"></td>
    <td><input type = "Radio" Name ="vote1['.$var.']" value= "abdul"></td>

然后在处理表单时,变量$_POST['vote']$_POST['vote1']将是包含每行单选按钮值的数组。您可以遍历它们并将它们插入数据库。

于 2012-12-30T17:26:04.503 回答