Solved

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

Posted on 2016-07-18
1
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 110

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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.

627 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