I trying to add a question from Question Bank.But it throwing an error.Can any one mention how to rectify this error,I have no programming skills.
Screen shot of the error is below.
We need a lot more information:
What version of Moodle?
Does this happen for every single quiz? Every single course?
Do you have questions in the question bank?
Looks like you are using Remui theme - if you switch to Boost, does it still throw the error?
Here are answers for the above questions:
Moodle Version 3.5
It happens in All Quiz created in that particular course(Unable to add questions from question bank),Other Courses quiz questions can be added from question bank without any error.
Yes We have questions , nearly 50 questions (Which are imported into question bank using Upload format .txt)
Yes theme is changed to Boost,The same error occurred in that theme also.Screenshot of that is attached below.
What are the question types? Can you export them as xml and post them here (or a small sample)
I just tried to export my question bank into xml format,But it is also throwing an error.
Steps of export is given below.
Step 2:
With in fraction of seconds the gets reloaded to below screen
Actually there are 223 question in my question bank.
Below is the format, Previously before uploading the below attachment my question used to work fine but after uploading below files error started.
It sounds like something might have corrupted in your question upload. Can you access just the question bank? You might delete the questions and try and import again or, as Marcus suggested, try exporting the questions to share with us.
Iam also unable to delete question bank,It showing an error("Can not find data record in database table qtype_multichoice_options..") Is there any other alternate way to delete question, My on going quiz should not disturb.
Hello Chetusvi,
Here is what happened:
Your text file has a mistake on the second question:
A sum of money at compound interest amounts to thrice itself in 3 years. In how many years will it be 9 times itself?
A. 12
B. 9
C. 6
D.3
ANSWER: C
I don't know if you see it now but on the line D.3 there is a missing space between the dot and the 3 it should be D. 3
Unfortunately some of the questions import formats are not very robust (I think this should really be corrected, during my tests I was able to reproduce such problems with both the Aiken and Gift import formats but maybe other are prone to the same breakage maybe I should create an issue in the tracker for that ?)
So as a result a broken question was created in the database: there is a record in the (yourprefix)_question table with no matching record in the (yourprefix)_qtype_multichoice_options table.
To make your problem worse there is currently a bug in Moodle 3.4 and 3.5 that break the display of the question bank when there is a brken question in the database! See MDL-62811 issue for the details. Fortunately developers have made some work to fix this issue and it is currently in testing so if the testing don't reveal any problem it will be integrated in this week release (or next week)
But unless you or your administrator are able to upgrade your Moodle instance to Moodle 3.5.1+ after this issue is closed this will not solve your problem.
I think that, unfortunately, the only solution is to use some tool like phpMyAdmin (or PgAdmin if your database is PostgreSQL) to directly delete the record in the (yourprefix)_question that has no associated record in (yourprefix)_qtype_multichoice_options.
I can guide you if you have never done this before but don't forget to backup your database and your whole Moodle webiste first just to be carefull
PS: I use (yourprefix) in the table'names because it is usually mdl_ but can be different on some Moodle installations. So most likely for you the tables will be mdl_question and mdl_qtype_multichoice_options
Hello Jean-Michel Védrine,
I would be very happy to get guidance to delete that record directly,So that this problem may be solved in my moodle. Yes I have taken backup of moodle site.
Thanks.
Hello,
So the first step is to verify if your database is MySQL, MariaDB, PostgreSQL, or any other database.
Then verify if you have the needed tool to do queries on your database like PhpMyAdmin for MySQL installed
Once this is OK, verify that you can access the place where you can type a SQL query (in PhpMyAdmin it's the "SQL" tab) and verify that you can do some basic query like
SELECT * FROM mdl_question
of course if your prefix is not mdl_ (you will see it in the table list) you will have to change the mdl_question name to something else
Sorry if you already know all this
Then we can start the real thing
Execute the query (better to copy it not to make any typo)
SELECT t1.id, t1.name
FROM mdl_question t1
LEFT JOIN mdl_qtype_multichoice_options t2 ON t1.id = t2.questionid
WHERE t1.qtype='multichoice' AND t2.id IS NULL
Here also if your prefix is not mdl_ you will have to change the mdl_question and mdl_qtype_multichoice_options names
Hopefully if my guessing is correct this will return a single record with D.3 as name (this is because of the broken line in your import file)
Note the number displayed in the id column for that record (in my case when I tested your txt import file it was 308 but of course your result will be different).
Click on the Search tab and enter the id number that you noted in the previous step and click on "Execute" button
If you have not make any mistake, the broken record with D.3 as name and question text should be displayed and all you have to do is to click on the delete button for that record. You are done.
My procedure is certainly not the quickest one, but I think that for people not familiar with database actions, it is safer because you don't risk deleting unwanted records, by first doing a search and then manually deleting the record the risk of deleting the wrong record or executing a wrong query are minimized.
If something is unclear don't hesitate to ask before doing anything but I will be far away from home until Sunday.
Thanks for everyone that helped. We also faced this issue at work and this discussion helped a lot.
One thing that I found out is that the question's corruption in the database prevents us from editing and deleting it, but not from moving it. So, while we prepare the backups and all we need to go directly to the database, we created a "Garbage questions (don't use)" category below "System" and moved the problematic questions there. Now there's no more corrupted question inside the course's question bank so inserting questions from the bank to a quiz is working. I don't know if there's any adverse side effects to this, though.
Using Moodle 3.5.1 (Build: 20180709)
It's happen when I import moodle multiple question XML format , but the XML didn't include the answer (my mistake when creating XML format). The question imported with no answer option. The question can not deleted. So I did delete with SQL.
delete from mdl_question where id IN
(
SELECT
aa.id
FROM
(select DISTINCT id from mdl_question) AS aa
LEFT JOIN mdl_qtype_multichoice_options bb ON aa.id = bb.questionid
WHERE
bb.questionid IS NULL
)