diff --git a/blog/index.php b/blog/index.php
index <HASH>..<HASH> 100644
--- a/blog/index.php
+++ b/blog/index.php
@@ -63,9 +63,9 @@ if ($entryid and !isset($userid)) {
     $userid = $entry->userid;
 }
 
-if (isset($userid) && !isset($courseid)) {
+if (isset($userid) && empty($courseid)) {
     $context = context_user::instance($userid);
-} else if (isset($courseid) && $courseid != SITEID) {
+} else if (!empty($courseid) && $courseid != SITEID) {
     $context = context_course::instance($courseid);
 } else {
     $context = context_system::instance();
MDL-<I> blog: prevent index throwing errors with 0 courseid

Regression from MDL-<I> where Dave made the page not handle courseid = 0
and so now some urls will send you back to a db error..