Link to home
Start Free TrialLog in
Avatar of NeverEndingFlashStories
NeverEndingFlashStories

asked on

Is there an obvious syntax error in this short php code?

Hi,

I am using a CMS (moodle) which apparently has a built in function is_enrolled()  to verify that the user is enrolled in the course. The function definition and example is here : Function definition

I am trying to use it but it keeps returning 'not enrolled' when the user is actually enrolled. Since I am not really good at php, i am trying to figure out whether i may have not written this right. The link that the user clicks returns the GET, domain.com/x.php?tomato=2&potato=2


x.php

$courseid = $_GET["tomato"];
$userid = $_GET["potato"];
function isuserenrolled($courseid, $userid) {
	$context = context_course::instance($courseid); 
	return is_enrolled($context, $userid, '', true);
}
if (isuserenrolled($courseid, $userid)) {
	echo 'is enrolled';
}
else {
	echo 'not enrolled';
}

Open in new window


the $context is a function that is copied straight from here

Help.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial