Solved

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

Posted on 2016-07-18
1
50 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 108

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now