General developer forum

ERROR: Incorrect number of query parameters. Expected 3, got 2

 
Picture of JC Dodo
ERROR: Incorrect number of query parameters. Expected 3, got 2
 

Hi,

After upgrading my Moodle from version 3.0+ to 3.3.5 and block_studentstracker from 2015051100 to 1.5 (2017062200), when viewing one of my courses is showing error message below. I will appreciate if you can help and advise? Thanks!


Warning: Invalid argument supplied for foreach() in /path/to/moodle/blocks/studentstracker/locallib.php on line 36

ERROR: Incorrect number of query parameters. Expected 3, got 2.

Debug info: 

Error code: invalidqueryparam

Stack trace:

line 913 of /lib/dml/moodle_database.php: dml_exception thrown

line 1211 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->fix_sql_params()

line 1558 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()

line 1631 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()

line 1841 of /lib/dml/moodle_database.php: call to moodle_database->get_field_sql()

line 42 of /blocks/studentstracker/locallib.php: call to moodle_database->count_records_sql()

line 117 of /blocks/studentstracker/block_studentstracker.php: call to studentstracker::has_role()

line 288 of /blocks/moodleblock.class.php: call to block_studentstracker->get_content()

line 230 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()

line 1205 of /lib/blocklib.php: call to block_base->get_content_for_output()

line 1257 of /lib/blocklib.php: call to block_manager->create_block_contents()

line 579 of /lib/outputrenderers.php: call to block_manager->ensure_content_created()

line 39 of /theme/bootstrapbase/renderers/core_renderer.php: call to core_renderer->standard_head_html()

line 46 of /theme/lambda/layout/columns3.php: call to theme_bootstrapbase_core_renderer->standard_head_html()

line 1162 of /lib/outputrenderers.php: call to include()

line 1092 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()

line 244 of /course/view.php: call to core_renderer->header()


 
Average of ratings: -
Picture of Nitesh Kumar
Re: ERROR: Incorrect number of query parameters. Expected 3, got 2
 

Hi Jc,

open the blocks.studentstracker/locallib.php file and check the line #42. error is with query param.

Try debugging the query like this 

$DB->set_debug(true);

 $r = $DB->count_records_sql("SELECT COUNT(id) FROM {role_assignments} WHERE roleid IN($roles) AND contextid=? AND userid=?", $params);

$DB->set_debug(false);

 
Average of ratings: -
Picture of JC Dodo
Re: ERROR: Incorrect number of query parameters. Expected 3, got 2
 

Hi Nitesh,

I tried to add that line as you suggested and there is no similar output at all. The error message still the same as what I have posted above. Or is there somewhere else that I can expect to view the debugging message?

Thanks!



 
Average of ratings: -
Picture of Nitesh Kumar
Re: ERROR: Incorrect number of query parameters. Expected 3, got 2
 

Hi Jc,


The issue in these two lines.


line 42 of /blocks/studentstracker/locallib.php: call to moodle_database->count_records_sql()

line 117 of /blocks/studentstracker/block_studentstracker.php: call to studentstracker::has_role()


Try to print the variable which are using in these lines.

 
Average of ratings: -
Picture of JC Dodo
Re: ERROR: Incorrect number of query parameters. Expected 3, got 2
 

Hi Nitish,

I am still learning PHP and would appreciate if you can teach me how to fish.

Thanks smile

 
Average of ratings: -
Picture of JC Dodo
Re: ERROR: Incorrect number of query parameters. Expected 3, got 2
 

Managed to fix it. Details on github comment of this maintainer author.

 
Average of ratings: -