add the anchor at the end of the action:
"<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>#<id val>"
where <id val> is the product ID.
nothing needs to be done to the continue shopping code.