$sql_tbl must be present (did you check?). Try adding this before the foreach:
However, I have two concerns with this customization: database queries should not be in a loop if you can help it, especially one like this that could have a lot of products; and Extra Fields returned to product listings in 4.1, so the data is already there (
https://forum.x-cart.com/showthread.php?p=118321#post118321 [watch for typos]).