Solved

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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

840 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