我正在尝试使用每行的不同提交按钮将不同行表的数据保存在数据库中。
echo '<form style="text-align:center" id="form1" name="form1" method="post" action="">';
echo "<tr>";
echo "<td nowrap='nowrap'><label>".$rowsum['student_name1']."</label><input type='hidden' name='studentId1' id='studentId1' value=".$rowsum['student_name1']." /></td>";
echo "<td align='center'>
<select id='Status1' name='Status1'><option value='NP'>Not Present</option><option value='P'>Present</option></select></td>";
echo "<td align='center'>
<input style='font-weight:bold; background:#FFFFFF; text-align:right; color:#000000;' disabled='disabled' name='mar1' type='text' id='mar1' size='5' maxlength='5' value='".$mar1."' /></td>";
echo "<td align='center'>
<input style='font-weight:bold; background:#FFFFFF; text-align:right; color:#000000;' disabled='disabled' name='hin1' type='text' id='hin1' size='2' maxlength='2' value='".$hin1."' /></td>";
echo "<td align='center'>
<input style='font-weight:bold; background:#FFFFFF; text-align:right; color:#000000; border:hidden;' type='text' id='eng1' disabled='disabled' name='eng' value='".$eng1."' size='2' maxlength='2' /></td>";
echo "<td align='center'>
<input style='font-weight:bold; color:#000000; background:#FFFFFF; text-align:right; border:hidden;' name='hist1' id='hist1' value='".$hist1."' disabled='disabled' size='2' maxlength='2' /></td>";
echo "<td align='center'>
<input style='font-weight:bold; background:#FFFFFF; text-align:right; color:#000000; border:hidden;' name='geo1' id='geo1' value='".$geo1."' disabled='disabled' size='5' maxlength='5' type='text' /></td>";
echo "<td align='center'>
<input style='font-weight:bold; background:#FFFFFF; text-align:right; color:#000000; border:hidden;' type='text' name='marks1' disabled='disabled' id='marks1' value='".$marks1."' size='5' maxlength='5' /></td>";
echo "<td align='center'>
<input type='submit' name='SaveBat1' id='SaveBat1' value='Save' />
</td></tr>";
echo '</form>';
//}
$sql_result1 = mysql_query("SELECT `student_name` FROM `bat_score_board` WHERE `student_name` = '$student1'") or die(mysql_error());
$sql_row1 = mysql_fetch_assoc($sql_result1);
if(!empty($sql_row1['student_name'])) {
//echo "Id exists - " . $sql_row1['student_name'] . "\n";
$sqlup1 = "update bat_score_board set student_name='$student1', status='$status1', mar='$mar1', hin='$hin1', eng='$eng1', hist='$hist1', geo='$geo1', marks='$marks1' where student_name='$student1'";
$resultup1 = mysql_query($sqlup1);
//print_r($resultup1); exit();
} else {
//echo "Id no longer exists - " . $sql_row1['student_name'] . "\n";
$sqlBat1 = "INSERT INTO bat_score_board(student_name, status, mar, hin, eng, hist, geo, marks)VALUES('$student1', '$status1', '$mar1', '$hin1', '$eng1', '$hist1', '$geo1', '$marks1')";
$resultBat1 = mysql_query($sqlBat1);
//print_r($resultBat1); exit();
}
这是我使用 PHP 为每一行尝试的(每行具有不同的名称、id 等)但是当我按下第一行的提交按钮以将第一行的数据保存到数据库中时它成功保存但是当我按下第二个提交按钮时当时我提交的第一行的数据在数据库中获得“0”(零),第二行的同一时间数据保存在不同行的数据库中。
再次提交后,我尝试保存第一行的数据,当时第一行的数据被保存,但第二行的数据得到“0”。谁能告诉我哪里出错了?