Moodle Course custom field data not save

Jibon Bikash Roy
Jibon Bikash Roy used Ask the Experts™
on
I have added a custom field in course page.

my form input code is in /course/edit_form.php

        $mform->addElement('text','course_price', get_string('course_price'),'maxlength="100"  size="10"');
        $mform->addHelpButton('course_price', 'course_price');
        $mform->setType('course_price', PARAM_RAW);
        if (!empty($course->id)) {
            $mform->hardFreeze('course_price');
            $mform->setConstants('course_price', $course->course_price);
        }

/course/lib.php

  $data->course_price  = !empty($data->course_price) ? $data->course_price :0;

// save data
$newcourseid = $DB->insert_record('course', $data);



but data not save in DB course table, give the error Error writing to database. Can anybody help me?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
give the error Error writing to database
What error?  Please copy and paste the error message, thanks.

My guess is that you want something not  like this:

$newcourseid = $DB->insert_record('course', $data);

but instead like this:

$newcourseid = $DB->insert_record('course', $data->course_price);
Most Valuable Expert 2011
Top Expert 2016

Commented:
stale question

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial