Support Forums
Development Forum
supplied argument is not a valid MySQL-Link resource
You must be signed-in to post.
| Author | Subject | |
|---|---|---|
| Page: 1 | ||
joshua_howell![]() | Subject: supplied argument is not a valid MySQL-Link resource | |
| I am trying to write some code to test if the users number of test attempts on the current test exceeds a value but i am getting errors in mysql query (see below for message). I guess it isn't connecting to the database but i'm not sure. Is $db a global variable or do i need to tell it to be loaded in the file. The code has been added to the file ATutor\themes\default\test_questions\truefalse_result.tmpl.php , is this an issue? Things to describe: Operating system ATutor is installed on - Windows XP pro ATutor version - 1.6.2 Patch #s applied - all patches upto 25 ATutor theme name - custom PHP version - 5.2.5 MySQL version - 5.0.51 Webserver & version - XAMPP 1.6.5 Copies of error messages - "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\ATutor\themes\default\test_questions\truefalse_result.tmpl.php on line 54" Changes to default settings - some custom patches to alter results output. Web browser being used - Firefox 3.0.13 Posted: 2009-08-06 23:27:38 | ||
greg![]() | Subject: Re: supplied argument is not a valid MySQL-Link resource | |
| You generally do not query the db from within a template, but rather do it in an associated script and pass the values to the template via the $this->savant->assign() object. Have a look at the TruefalseQuestion class include/classes/testQuestion.class.php Posted: 2009-08-07 09:12:30 | ||
joshua_howell![]() | Subject: Re: supplied argument is not a valid MySQL-Link resource | |
| Thank you for the reply Greg. I added the following code to the "assignDisplayResultVariables" function in the include/classes/testQuestion.class.php file but i am still getting the same error. /*protected */function assignDisplayResultVariables($row, $answer_row) { $this->savant->assign('base_href', AT_BASE_HREF); $this->savant->assign('answers', $answer_row['answer']); $this->savant->assign('row', $row); /* count the number of test attempts for the current test */ $current_user = $_SESSION['member_id']; $current_test = $_GET['tid']; $sql = "SELECT COUNT(result_id) FROM ".TABLE_PREFIX."tests_results WHERE member_id = $current_user AND test_id = $current_test"; $result = mysql_query($sql, $db); $this->savant->assign('attempt_number', $result); } The error is; Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\ATutor\include\classes\testQuestions.class.php on line 805 Line 805 is; "$result = mysql_query($sql, $db);" Any ideas on what i am doing wrong? Posted: 2009-08-13 03:15:48 | ||
greg![]() | Subject: Re: supplied argument is not a valid MySQL-Link resource | |
| $result is a resource rather than a value. Get the value out of $result with mysql_fetch_row() etc. then pass its value to that template. You might also need single quotes around the $current_user and $current_test variables in your sql statement. Turn on debugging and use the debug() function to output various values. Turn it on at the top of the include/vitals.inc.php file. See the developer documentation for details Posted: 2009-08-17 15:36:31 | ||
| Page: 1 | ||
You must be signed-in to post.



