In molten sodium chloride, the only available ions are Na+NaX+ and Cl−ClX−. With electrolysis, the products will be sodium metal and chlorine gas.
In an aqueous solution, the sodium chloride still moves the charges from one electrode to the other, but the potential for electrolysis of water is less than Na+NaX+or Cl−ClX−. So the products of a solution of sodium chloride is hydrogen gas and oxygen gas.