0

问题的当前摘要:我正在从表“main”中提取信息,其中列出了特定 ID 的目标编号和目标名称(最多可以有 10 行)。这些显示在网页上的表格中。我在第一列中添加了反映表中行数的复选框。代码如下,这部分工作正常。输出为 3 列,复选框、目标编号、目标名称,以及最多 10 行,具体取决于表中该特定 ID 的信息量。

目标.php

<tr>
        <td valign=top colspan=3>
            Current Goals<br>
                <?php
                //this data is being pulled from 'main'
                    $result = mysql_query("SELECT * FROM main WHERE idnumber = $idnumber ORDER BY goalnumber");
                    if ($result) {
                    $total_rows = mysql_numrows($result);
                    } else { $total_rows = 0; }
                    print "<table border=1 width=400>\n";
                    print "<tr> \n";
                    print "<th> Checkbox </th> \n";
                    print "<th> Goal Number </th> \n";
                    print "<th> Goal Name </th> \n";
                    print "</tr> \n";
                    //}
                    $i = 0;
                    while ( $i < $total_rows )
                    {
                    $goalno = intval(mysql_result($result, $i, "goalnumber"));
                    $goalname = mysql_result($result, $i, "goalname");
                    $goal_id = intval(mysql_result($result, $i, "goal_id"));
                    print "<tr> \n";
                    print "<td> <center><input type=\"checkbox\" name=\"goal_id_$i\" value=\"$goalnumber - $goalname\"></td> \n";
                    print "<td> $goalnumber </td> \n";
                    print "<td> $goalname </td> \n";
                    print "</tr> \n";
                    $i = $i + 1;
                    }
                ?>
                </table>
        </td>

一旦用户选中这些复选框中的 1-10 个并提交表单,我需要将所述选择的值传递给数据库(每个选择都应写入数据库表“updated_goals”中的一个新字段。在提交​​时下面的文件被调用。请注意,我正在将复选框值写入同一个数据库“updated_goals”中的不同表。我不确定代码哪里出错了,但目标是写入复选框的值,将“$goalnumber - $goalname”放入goal_id 字段。

目标提交.php

// process data in table: updated_goals
$query = "SELECT idnumber from updated_goals where idnumber = {$_POST['idnumber']}";
$result = mysql_query($query);
$total_rows = mysql_numrows($result);

            //writing data to 'updated_goals'

        if (isset($_POST ['goal_id_$i'])) { $goal_id = ReplaceQuotes($_POST['goal_id_$i']); } else { $goal_id = ""; }

    $query = "INSERT INTO updated_goals ( ";
    $query .= "goal_id ";
    $query .= ") VALUES ( ";
    $query .= "'$goal_id' ";
    $query .= ")";
4

1 回答 1

1

可能的解决方案:

更改此行:

if (isset($_POST ['goal_id'][$i])) { $goal_id = ReplaceQuotes($_POST['goal_id'][$i]); } else { $goal_id = ""; }

if (isset($_POST ['goal_id_'.$i])) { $goal_id = ReplaceQuotes($_POST['goal_id_'.$i]); } else { $goal_id = ""; }

或更改此行

print "<td> <center><input type=\"checkbox\" name=\"goal_id_$i\" value=\"$goalnumber - $goalname\"></td> \n";

print "<td> <center><input type=\"checkbox\" name=\"goal_id[$i]\" value=\"$goalnumber - $goalname\"></td> \n";

如果数组用于输入名称,例如: inputname[] 它可以通过 $_POST['inputname'][index] 或 $_GET['inputname'][index] 通过 POST 或 GET 获取

于 2013-01-28T16:16:58.360 回答