diff --git a/admin/browse.php b/admin/browse.php index 86633618faa..8f00ef33c50 100644 --- a/admin/browse.php +++ b/admin/browse.php @@ -555,7 +555,8 @@ if ($private == "N") { $SQL = "Select * FROM {$dbprefix}tokens_$surveyid WHERE token=?"; - if ($SQLResult = db_execute_assoc($SQL, $dtrow['token'])) + if ( db_tables_exist("{$dbprefix}tokens_$surveyid") && + $SQLResult = db_execute_assoc($SQL, $dtrow['token'])) { $TokenRow = $SQLResult->FetchRow(); } diff --git a/common.php b/common.php index f2f3e566dce..49ef2d16931 100644 --- a/common.php +++ b/common.php @@ -389,6 +389,27 @@ function db_select_tables_like($table) } } +/* + * Return a boolean stating if the table(s) exist(s) + * Accepts '%' in names since it uses the 'like' statement + */ +function db_tables_exist($table) +{ + global $connect; + + $surveyHasTokensTblQ = db_select_tables_like("$table"); + $surveyHasTokensTblResult = db_execute_num($surveyHasTokensTblQ); + + if ($surveyHasTokensTblResult->RecordCount() >= 1) + { + return TRUE; + } + else + { + return FALSE; + } +} + /** * getsurveylist() Queries the database (survey table) for a list of existing surveys * @global string $surveyid