Adding a new field in table of moodle 2.4 database

Adding a new field in table of moodle 2.4 database

by hina yousuf -
Number of replies: 9

Hi!

I am using moodle 2.4. I want to add a field in the user table with the name GPA. To add this i am adding a form element in /user/editlib.php and adding a field with name gpa in user table. I used to follow the same steps in moodle 2.0 but this does not work in moodle 2.4. What else do i have to do to add a new field. I don't want to add a custom profile field.

To add a new field in the some other table and then using insert record to insert record also gives error i-e user fields not defined. Please tell me where i am going wrong?

 

Average of ratings: -
In reply to hina yousuf

Re: Adding a new field in table of moodle 2.4 database

by Michael Gwynne -

Why do you want to add a new field to the user table instead of using a custom profile field?

If you change the database structure, you may have problems upgrading to future versions of Moodle

In reply to Michael Gwynne

Re: Adding a new field in table of moodle 2.4 database

by hina yousuf -

I want to create a profile form in two steps like allow user to fill in two pages.some of the field will be on second page. I want to customize the form using custom fields how can I display some of the fields on second form and some custom fields on first page.

I want to know how to add a new field in user table. Where is the structure of user table defined in code. How is it possible?

In reply to hina yousuf

Re: Adding a new field in table of moodle 2.4 database

by Michael Gwynne -

I would create a custom profile field instead of altering a core table of Moodle.

If I were modifying the login page in such a way, I would create a brand new login page rather than modify the existing one. I would then change the alternative login URL (found at /admin/settings.php?section=manageauths) to point at my custom login page.

Hope that helps

In reply to Michael Gwynne

Re: Adding a new field in table of moodle 2.4 database

by andriya edward -

Hi 

         I am using 2.8 moodle version.I need to add a new field to the form and insert it to the table.Do I need to change the database structure? 

In reply to andriya edward

Re: Adding a new field in table of moodle 2.4 database

by Balvant Ramani -

How to add custom field to question table ?how to Create custom module via code? I want to add question level field to question and user level field to user. when user select quiz i want to generate question as per matching level.
I add user profile field to user. But unable to add field to question.

Please Help.

In reply to Balvant Ramani

Re: Adding a new field in table of moodle 2.4 database

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Your question is too vague to give a meaningful answer. What has your research found so far, and what have you tried to do so far?, what version of Moodle are you using, what is your background. There is a significant amount of document for Moodle programmers.  If you give more information we may be able to help.

In reply to hina yousuf

Re: Adding a new field in table of moodle 2.4 database

by deepak garg -

To add a new field to mdl_user table follow the simple following steps:-

Step-1:- Create a field in mdl_user named GPA (name you want to add) using mysql commands. For adding this you can use any mysql client like phpmyadmin or sqlyog etc.

"ALTER TABLE "table-name" ADD COLUMN "column-name" "column-value-type". "

Step-2:- Create a field in user/editlib as per your requirements but keep the name of the field same as the mdl_user table column.

Step-3:- thats it.

In reply to deepak garg

Re: Adding a new field in table of moodle 2.4 database

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Acutally, no:

Step-3:- live to regret it.

You missed out:

Step-0:- consider the implications of what you are about to do.

Average of ratings: Useful (1)