Not wrong, but not using teh vB coding standards and functions. Also, unless there is more code, you are not cleaning $forum_name before using it in a query, opening your board to SQL-Injections.
The "correct"

vB way to do this:
PHP Code:
$forum_name="$pagetitle"; // <-- This need to be cleaned before using it in a query!!!!
$row = $db->query_first("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title='$forum_name' LIMIT 1");
$forum_link="<a href=\"/forums/forumdisplay.php?f=".$row["forumid"]."\">$forum_name Forum</a>";