我已經完成了從數據庫中檢索數據的表單。這種形式允許你從數據庫中顯示學生名單,但問題是我無法單獨正確輸入他們的分數。它允許插入分數,但不幸的是,它只接受最後一名學生的最後一個分數,並向所有學生輸入相同的分數。選擇帶空白文本框的標籤
這是我的代碼:
FORM代碼
if ($result->num_rows > 0) { // output data of each row
while($row = $result->fetch_assoc()) {
if($row['status']=='p'){
<form name="result" method="post">
<?php { //this form will display the set of students
echo $row['lastname'] . ', ' . $row['firstname'];
echo '<input type="hidden" name="selected[]" value="'.$row['reviewee_idnumber'].'"/>'; ?>
<input type="text" name="score" required="required" size="20" placeholder="Score"/><br><br>
<?php echo '</br>';
}
} //if statement
} //while statement
?>
<input type="submit" name="submit" value="Submit"/>
<input type="hidden" name="code" value="<?php echo $code;?>"/>
<input type="hidden" name="subject" value="<?php echo $subject;?>"/>
<input type="hidden" name="items" value="<?php echo $items;?>"/>
<input type="hidden" name="date" value="<?php echo $date;?>"/>
</form>
這是我插入我的代碼插入到數據庫
if(isset($_POST['submit'])){
$code = $_POST['code'];
$subject = $_POST['subject'];
$items = $_POST['items'];
$date = $_POST['date'];
$score = $_POST['score']; //get score
$update = mysql_query("INSERT INTO exam (exam_code, subject, date, total_item)
VALUE ('$code','$subject', '$date', '$items')");
if(!empty($_POST['selected'])) {
$checked_count = count($_POST['selected']);// Counting number of checked checkboxes.
//echo "You have selected following ".$checked_count." option(s): <br/>";
foreach($_POST['selected'] as $selected){ // Loop to store and display values of individual inputs.
$updatedata="INSERT INTO result (score, exam_code, reviewee_idnumber)
VALUE ('$score', '$code', '$selected')";
if(@mysql_query($updatedata,$dbc)){
print '<p> successful!</p>';
}else{
print '<p> failed. '.mysql_error().'</p>';
}
它應該顯示列表中的學生(這是罰款)和在他們的名字旁邊是一個空白空間,將接受他們的分數(這是行不通的)。
感謝您的回覆。我試圖重新編碼
爲每個輸入字段使用不同的名稱 - 請參閱我更新的答案。 – Glorfindel
雖然仍然無法正常工作,但感謝您的想法!會更深入。乾杯! – Regina