当用户点击“保存”按钮但我收到这些错误消息时,我正在尝试将表单中的数据插入到数据库中:
注意:未定义的索引:第5行的C:\ moodleFile \ server \ moodle \ local \ try \ process.php中的名称
注意:第6行的C:\ moodleFile \ server \ moodle \ local \ try \ process.php中的未定义索引:university_id
致命错误:在第15行的C:\ moodleFile \ server \ moodle \ local \ try \ process.php中的非对象上调用成员函数insert_record()
这些是用户单击“保存”按钮时调用的文件代码:
<?php
global $DB;
$name = $_POST['name'];
$uni_id = $_POST['university_id'];
$record1 = new stdClass();
$record1->name = $name;
$record1->displayorder = '10000';
$record2 = new stdClass();
$record2->name = $uni_id;
$record2->displayorder = '10000';
$records = array($record1, $record2);
$lastinsertid = $DB->insert_record('tbl_faculty', $records);
if(!$lastinsertid)
{
echo "Could not insert";
}
?>
我是Moodle的新手可以有人帮帮我吗?感谢。
答案 0 :(得分:2)
// Include config.php at the top of any user facing code.
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
// Never trust input from the web, always use optional_param() or required_param() and specify the value type.
$name = optional_param('name', null, PARAM_TEXT);
$uni_id = optional_param('university_id', null, PARAM_TEXT);
$record1 = new stdClass();
$record1->name = $name;
$record1->displayorder = '10000';
$record2 = new stdClass();
$record2->name = $uni_id;
$record2->displayorder = '10000';
// Insert one record at a time.
$lastinsertid1 = $DB->insert_record('faculty', $record1);
$lastinsertid2 = $DB->insert_record('faculty', $record2);