Moodle Course custom field data not save

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->setConstants('course_price', $course->course_price);


  $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?
Jibon Bikash RoyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
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);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
stale question
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.