Solved

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

Posted on 2016-07-18
1
55 Views
Last Modified: 2016-07-22
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.
0
Comment
1 Comment
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41717958
There is no syntax error in the code snippet posted above, in the sense that PHP will parse the script and try to execute it.  Whether it is usable in the context of the Moodle project is a separate question.  Moodle undoubtedly has some pockets of expertise but it is kind of arcane when compared to the mainstream systems like WordPress, Drupal or Laravel.  You might want to look for a local Moodle user group and get involved to share ideas with other developers.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question