Just a thought... try changing this:
Code:
$posted = $vbulletin->db->query_first("SELECT userid FROM " . TABLE_PREFIX . "post where threadid = " . $vbulletin->GPC['threadid'] . " AND userid = " . $vbulletin->userinfo['userid'] . "");
to this:
Code:
$posted = $vbulletin->db->query_first("SELECT userid FROM " . TABLE_PREFIX . "post where threadid = " . $vbulletin->GPC['threadid'] . " AND userid = " . $vbulletin->userinfo['userid'] . ";");
Can you try the query itself (with substitutes) in phpmyadmin?