我正在尝试为 moodle 中的学生提问自定义plugin
。为此,我有两张桌子。 mdl_qadt and mdl_qads.
我做了老师部分,也就是老师可以添加问题。这将保存到表mdl_qadt
。现在学生登录并选择此活动显示表格。学生可以在这里发布答案。发布给出错误的答案时:
写入数据库时出错。
但答案和相关数据已插入表格mdl_qads
。那么为什么错误显示??
错误页面图片
学生表格的图片
View.php
echo $OUTPUT->heading($qadt->name);
if ($qadt->intro) { // Conditions to show the intro can change to look for own settings or whatever
echo $OUTPUT->box(format_module_intro('qadt', $qadt, $cm->id), 'generalbox mod_introbox', 'qadtintro');
}
echo "<b>". $qadt->question ."</b>";
require_once(dirname(__FILE__).'/stud_form.php');
$stud_form = new student_form("stud_action.php?id={$cm->id}&ref={$qadt->id}");
$stud_form->display();
echo $OUTPUT->footer();
stud_form.php
require_once($CFG->dirroot.'/lib/formslib.php');
class student_form extends moodleform {
function definition () {
$mform =& $this->_form;
//$mform->addElement('header', 'general', 'general');
$mform->addElement('text', 'answer', 'Your answer');
$mform->setType('answer', PARAM_TEXT);
$mform->addRule('answer', null, 'required', null, 'client');
$this->add_action_buttons(false, 'submit');
}
}
stud_action.php
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once($CFG->dirroot.'/lib/formslib.php');
$answer = $_REQUEST['answer']; //answer given by student or user
if(isset($_GET['ref']))
{
$refid = $_GET['ref']; // refid
}
if(isset($_GET['id']))
{
$modid = $_GET['id']; // module id
}
$currentTime = date('Y-m-d H:i:s');
$record = new stdClass();
$record->sid = $USER->id; // logged in user's id
$record->refid = $refid;
$record->answer = $answer;
$record->modified_date = $currentTime;
$table = "qads";
$data = studResponse($record, $table);
function studResponse($record, $table)
{
global $DB;
$lastinsertid = $DB->insert_record($table, $record);
return $lastinsertid;
}
if($data)
{
header("location:view.php?id=$modid");
}
即使将数据插入表中,我也会收到错误。我怎样才能解决这个问题。?任何帮助都很明显。
修改
我收到以下错误
Debug info: unknown error fetching inserted id
[NULL]
Error code: dmlwriteexception
Stack trace: •line 1101 of \lib\dml\mysqli_native_moodle_database.php: dml_write_exception thrown
•line 1144 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
•line 52 of \mod\qadt\locallib.php: call to mysqli_native_moodle_database->insert_record()
•line 18 of \mod\qadt\stud_action.php: call to students_response()