You just invented a fuel cell vehicle. Creating hydrogen from water requires a lot of energy, though, so that’s not feasible to do in a car. Theoretically you could use solar panels but then you’d need a truck for all the equipment and a couple of days of collecting sunlight for a tank full.