We went into Afghanistan because the Taliban were harboring Al Qaeda. We went into Iraq because of false claims about weapons of mass destruction. Japan, Germany, and italy had a formal alliance during WW II. There was no alliance between Afghanistan and Iraq.
They were two separate wars.