Yes, a bad spark plug can cause an engine error code. A misfire on a specific cylinder will trigger an error code for that cylinder.