WordPress $wpdb no result

Your specific issue in that code is that you’re missing the quote marks around the $code.

$query .= 'WHERE code=".$code;

Should be:

$query .= "WHERE code= "'.$code.'"';

In the long run, you should indeed use prepare() properly, but this is the specific problem with the code you posted.