php - Can't insert into database using data manipulation API-Moodle -


i'm trying insert data form database when user clicks on save button i'm getting these error messages:

notice: undefined index: name in c:\moodlefile\server\moodle\local\try\process.php on line 5

notice: undefined index: university_id in c:\moodlefile\server\moodle\local\try\process.php on line 6

fatal error: call member function insert_record() on non-object in c:\moodlefile\server\moodle\local\try\process.php on line 15

these codes of file called when user clicks on save button:

<?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"; }  ?> 

i'm new moodle can me out please? thanks.

// include config.php @ top of user facing code. require_once(dirname(dirname(dirname(__file__))) . '/config.php');  // never trust input web, use optional_param() or required_param() , specify 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 1 record @ time. $lastinsertid1 = $db->insert_record('faculty', $record1); $lastinsertid2 = $db->insert_record('faculty', $record2); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -