$choice = array(); for ($i = 0; strlen($_POST["choice{$i}"]) > 0; ++$i) { $choice[$i] = array($_POST["choice{$i}"], isset($_POST["correct{$i}"]) ? 'true' : 'false', isset($_POST["exclusive{$i}"]) ? 'true' : 'false'); } $db->begin(); try { if (($subject = $_POST['subject']) == 0) { $newsubject = $_POST['newsubject']; try { $subject = $db->insertSubject($newsubject); } catch (Exception $e) { echo "<center>Không thể đặt tên <b>Môn</b> mới là '{$newsubject}'.</center>"; throw $e; } } $questionID = $db->updateQuestion($q, $question, $subject, isset($_POST['shuffleable']) ? 'true' : 'false', 0.5); foreach ($choice as $c) { $db->insertChoice($questionID, $c[0], $c[1], $c[2]); } $db->commit(); //echo "<center>Chỉnh sửa câu hỏi thành công!</center>"; header("Location: question_edit.php?q={$questionID}"); return; } catch (Exception $e) { $db->rollback(); ?> <center>Không thể sửa <b>Câu hỏi</b> mới.</center> <center>Xin hãy kiểm tra thông tin đã nhập.</center> <center><button onClick='history.back()'>Trở lại</button></center> <?php echo $e->getMessage();