A solution contains two sets of ions: the ions from the dissolved compound, and H+ and OH- ions from the water. Inert electrodes (graphite or platinum) conduct but do not take part, so only the ions in the solution react. Each electrode discharges one product.
Two rules decide the products. At the cathode, a metal forms only if it is less reactive than hydrogen. If the metal is more reactive than hydrogen, then hydrogen gas forms instead. At the anode, a halogen forms if the solution contains halide ions. If there are no halide ions, oxygen forms instead.
Copper chloride solution. The ions present are Cu2+, Cl-, H+ and OH-. Copper is less reactive than hydrogen, so copper forms at the cathode as a pink-brown solid. Chloride ions are halide ions, so chlorine gas forms at the anode. Chlorine bleaches damp litmus paper.
Sodium chloride solution. Sodium is more reactive than hydrogen, so hydrogen gas forms at the cathode and burns with a squeaky pop. Chlorine forms at the anode again. The Na+ and OH- ions are left behind, so the solution that remains is sodium hydroxide solution.