We are trying to replace a lamp but the switch won’t turn it off. The old lamp had 3 cables but the new just has 2. The old lamp had a blue connected to the red. We tried different combinations (addind the red with the black and the red with the white) but nothing seems to work. Any ideas? (See photos below)
If you didn't do anything to the switch, then take a wire from the light, black?, and connect it to only the red. Take the other wire from the light,white?, and connect it only to the white wire. Cap the other wire.
Experimentation (trying combinations) is a rather bad idea. It can seem expedient at the time, but the nature of electrical is that there are many combinations which will work but will kill you. You should pause and research instead.
There are other wires in the back of the box. Those should be left alone.
I see a dimmer. Not every lamp is compatible with every dimmer, but every dimmer is designed to work with incandescent bulbs. You can't solve two problems at once, no matter how good you think you are. I would suggest substituting a simple $1 bare light bulb holder there with an incandescent light. The purpose is to figure out which wires are the correct ones, and confirm they do work. Then you can try the other light and troubleshoot its problem. There are "incandescent simulator" devices such as the Lutron LUT-MLC which can be wired in parallel with LED etc. lamps to help them work better with old dimmers.
The first thing we know about any electrical installtation is that there may be safety grounding. That is always green, green/yellow, bare, or the exposed metal of the boxes and parts. These always go together, and they are never anything else.
The second thing we know about any lamp is it needs a neutral wire (to return current to source). Neutral is not ground. North American color codes for neutral are white or gray (generally white).
There is a white coming out from the ceiling, and a white on the lamp. Connect them. Neutral is done and dusted.
All other wires are "hot" of one kind or another, and there are no further rules defining which hot is which.
Now what remains are 2 wires from the ceiling. These wires were not connected before. You never connect wires from the wall/ceiling to each other if they weren't before, because they have different functions (otherwise the person would not spend the money on the extra wire). That means one wire will be used, and the other will be capped off.
The other wire on the lamp obviously needs to connect to something for the lamp to work. We can't connect it to both remaining ceiling wires as discussed. So we connect to one or the other.
Typically there are two wires either because a) there are 2 switches separately controlling two aspects of the light/fan, or b) there is a switched-hot and an always-hot up there for some reason (e.g. a light on a switch but a fan on a pull chain). You can only connect the lamp to one or the other, as discussed.
Since they are both hot wires (not white or green) and the remaining lamp wire is hot, now we are ready for experimentation.
Generally, in case b), people prefer the color codes of black for always-hot and red for switched-hot. That is not required; there are no color codes except for the ones mentioned for neutral and ground. I would give red a try and see if it works. If that doesn't work, the only other choice is black.