尝试从数据库中更新和删除记录,但我的 $key 总是返回零。这是我的代码。如果我需要澄清任何事情,请告诉我。谢谢你。
请注意,我没有包括下面“while”的选择语句。
// Fetch rows:
while ($Row = mssql_fetch_assoc($result5)) {
$id = $Row['id'];
$notes = $Row['RejectedNotes'];
$first = $Row['FIRST'];
$last = $Row['LAST'];
$ssn = $Row['SSN'];
$psn = $Row['PSN'];
$dob = $Row['DOB'];
$distdocket = $Row['DistDocket'];
$releasedate = $Row['ReleaseDate'];
$releasetype = $Row['ReleaseType'];
$columnData4 = "<table class='footerTable'><tr><td class='footerFirst'>"
. $first . "</td><td class='footerLast'>"
. $last . "</td><td class='footerSSN'>"
. $ssn . "</td><td><input type='text' class='footerNMCD' name = 'psn[]' value = '"
. $psn . "'></td><td class='footerDOB'>"
. $dob . "</td><td class='footerCause'>"
. $distdocket . "</td><td><input type='text' class='footerRelease' name = 'releasedate[]' value = '"
. $releasedate . "'></td><td>"
. "<select name='relOptions[]' id='releaseOptions' class='footerEvent'>"
. "<option value='$releasetype'>$releasetype</option>"
. "<option value='Discharge'>Discharge</option>"
. "<option value='In-House Parole'>In-House Parole</option>"
. "</select></td>"
. "<td class='reason'>"
. "<button class='reason' onclick='openNotesBox(\"$notes\");'>View</button></td><td>"
. "<input type='checkbox' name='checkbox[]' value=\"$id\" />$id</td></tr>";
print $columnData4;
}
print "</form></table>";
// I know this is strange code, but it's what I had to do for Chrome.
if(isset($_REQUEST['resubmit']) || isset($_REQUEST['remove']))
{
$checkbox=$_POST['checkbox'];
$nmcd=$_POST['psn'];
$release=$_POST['releasedate'];
$relOptions=$_POST['relOptions'];
//HERE IS MY ISSUE!!! $key is always "0".
foreach ($checkbox as $key => $value)
{
$nmcd = $nmcd[$key];
$release = $release[$key];
$releasedate = substr($release, 0, 2) . "-" . substr($release, 2, 2) . "-" . substr($release, 4, 4);
$relOptions = $relOptions[$key];
if(isset($_REQUEST['remove']))
{
$del = "DELETE FROM submitted WHERE id='$value'";
$result = mssql_query($del);
}
else {
if(isset($_REQUEST['resubmit']))
{
$resub = "UPDATE submitted
SET PSN = '$nmcd', ReleaseDate='$releasedate', ReleaseType='$relOptions', Rejected='0'
where id='$value'";
$result = mssql_query($resub);
}
}
}
}