Table "mdl_kategori" does not exist

Table "mdl_kategori" does not exist

by Vivi Oktaviani -
Number of replies: 15
i want to insert record to database but when i submit button :

Table "mdl_kategori" does not exist

script code:

$table = 'mdl_kategori';

  $dataobject = new StdClass;

  $dataobject->idkategori = $idkategori;

  $dataobject->namakategori = $kategori;

  $rec=$DB->insert_record($table, $dataobject);


but i'm sure that table is exist.

Does anyone know what's wrong with this? sorry for my bad english =.=

thanx before

Average of ratings: -
In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

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

Your English seems fine smile. What part of Moodle does this relate to. Core moodle tables tend to have English names and my guess is that kategori is category in a language other than English (pure guess). Do you have a way of checking in the database for table names, e.g. phpMySQLAdmin if you are using php, or from the command line.


In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Michael Aherne -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Have you tried taking the "mdl_" prefix off your table name? If you're using the default configuration where $CFG->prefix is set to "mdl_" then you don't need it in your table name.

Average of ratings: Useful (3)
In reply to Michael Aherne

Re: Table "mdl_kategori" does not exist

by Vivi Oktaviani -

@ marcus when i check in phpmyadmin the table was exits. but when i try to insert record i have this message

message

in what file i can found core moodle table? if the table is not in english it's can work or not?

@ michael i'm using $CFG->prefix='mdl_' as default

In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

So as Michael suggests, try using

$table = 'kategori';

Moodle itself should add the prefix to the table name when using the $DB calls

Average of ratings: Useful (1)
In reply to Richard Oelmann

Re: Table "mdl_kategori" does not exist

by Vivi Oktaviani -
when i try this i got this message

message

In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

OK, then I'd go back to Marcus' original question and back to basics

'What part of Moodle does this relate to'

Is this from a plugin? Which one? Is it part of your own customisations?

A 'kategori' table (or 'mdl_kategori') is certainly not part of core moodle, so can you give some more details about where it is from, what it does and what you are trying to achieve, please?


Richard

In reply to Richard Oelmann

Re: Table "mdl_kategori" does not exist

by Vivi Oktaviani -

this ini my own customisation. i try to create new table and i want to insert the table.

describe the table :

desc

first time i create the table in phpmyadmin, but it doesn't work. then i try using plugin in mod/mymodule/db. but it's same result. i can't insert record to table. 

In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When you say you have created the table using  mod/mymodule/db, did you do this manually or did you use the xmldb editor built into Moodle (which makes sure you don't have any mistakes in the install.xml file + provides you with upgrade code for changing the existing structures when you release new versions of you plugin)?

Also, if you created an install.xml file (but no upgrade.php), did you uninstall + reinstall your plugin to get it to create the database table for you?

You also seem to be missing the required, standard field 'id' from your table (instead you have an 'idkategori' field listed) - there is a good chance that is the cause of your problems (something which the xmldb editor should point out to you).

In reply to Davo Smith

Re: Table "mdl_kategori" does not exist

by Vivi Oktaviani -

i try to replace idkategori to id. but it still can't insert record.

error

this is my install.xml

install

have you know what's wrong with this? or the table just can select record and  can't insert record? 

In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Yousuf Tafhim -

Change
$dataobject = new StdClass;
to
$dataobject = new stdClass();

Average of ratings: Useful (1)
In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Dimitar Ivanov -

Enable DB debugging to see what your query looks like.


Put this before you run the query:

$DB->set_debug(true);

Then turn off debugging after the query, so you get debugging information only for the query you are interested in.

$DB->set_debug(false);


Average of ratings: Useful (2)
In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Luis de Vasconcelos -

That means the "Table mdl_kategori does not exist" problem is now fixed and there is something else wrong in your code.

Turn the Moodle Debugging option up to Developer level so that you get a more detailed error message.

Then do a var_dump() on $idkategori; and $kategori; to see what values they contain. Do you see the values you were expecting? If not, check the code where $idkategori; and $kategori; is defined. In other words, make sure the $dataobject that you are passing to $DB->insert_record has got the correct data. The "invalid database query parameter value" part of the error message suggests that either $idkategori; or $kategori; is not valid and not what $DB->insert_record is expecting.

Average of ratings: Useful (1)
In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Vivi Oktaviani -

right now i can insert record to table. but i want to get value from textbox in form. 

  $kategori = $mform->getElement('kategori');

  $table = 'kategori';

  $dataobject = new stdClass;

  $dataobject->id = $idkategori;

  $dataobject->namakategori = $kategori;

  $rec=$DB->insert_record($table, $dataobject);


and this is my coding form

class form_input extends moodleform {

    public function definition() {

        global $CFG, $DB;

        $mform = $this->_form;

$mform->addElement('text', 'idkategori', 'Kategori');

$mform->setType('idkategori', PARAM_INT);

$mform->addElement('text', 'kategori', 'Nama Kategori');

$mform->setType('kategori', PARAM_NOTAGS);

$this->add_action_buttons();

    }

    function validation($data, $files) {

        return array();

    }

}


How to get value from textbox?

In reply to Vivi Oktaviani

Re: Table "mdl_kategori" does not exist

by Yousuf Tafhim -
For that you will have to instantiate the form and check that the the form has been posted. For details check out the Form API documentation

Average of ratings: Useful (1)