go to phpmyadmin, and see the id field's name in you topics table.
forumid is not in your forum_topics table.
and change this:
$query = sprintf("SELECT * FROM phpbb_topics WHERE forumid=10",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname));
into
$query = "SELECT * FROM phpbb_topics WHERE forumid=10",
i know that would be safer, but if you use it bad, that won't work..