General developer forum

Create custom page

Picture of Mark Johnson
Re: Create custom page
Core developersParticularly helpful MoodlersPlugin developers
$DB->insert_record will normally return the ID of the new record, using the auto-incrementing id field in your table.  It looks like you haven't included a field like this in your table, so I'm guessing that you're seeing the error as it can't get this ID value.

When adding or altering moodle database tables for your plugin, you should always use the XMLDB editor to create an install.xml file.  This will automatically add the required id field to your tables, as well as preventing other things that might cause errors when interacting with the database API.  It will also generate the PHP code you need for you upgrade scripts if you make changes to the database in the future.
Average of ratings: -