It is illegal to
learn Sihr whether to use it or protect yourself by it. (Part No. 1; Page No. 550) Allah (Glorified and Exalted be He) mentions in the Qur'an that learning it is an act of Kufr (disbelief). Allah (Exalted be He) says:
...teaching men magic and such things that came down at Babylon to the two angels, Hârût and Mârût, but neither of these two (angels) taught anyone (such things) till they had said, “We are only for trial, so disbelieve not (by learning this magic from us).”
The Prophet (peace be upon him) judged Sihr as one of the major sins and commanded us to avoid it. He said:
Avoid the seven great destructive sins ...
He included Sihr among them.
It is related in the Sunan (Hadith compilations classified by jurisprudential themes) of
Whoever ties a knot and blows on it has indeed committed sorcery and whoever commits sorcery has indeed committed Shirk (associating others with Allah in His Divinity or worship).
As for the saying you mentioned, "Learn Sihr and do not practice it", it is not a Hadith at all; neither a Sahih (a Hadith that has been transmitted by people known for their uprightness and exactitude; free from eccentricity and blemish) nor a Da`if (weak) one.May Allah grant us success. May peace and blessings be upon our Prophet Muhammad, his family, and Companions.