When I was praying salatul Dhuhr, I moved in my sajda after my obligatory dhikr (I went on to recite optional dhikr), but then I remembered that moving invalidates it, so I stopped, is it valid?

I noticed this happens recently, where I had to repeat salatul fajr twice because I moved in my sajda due to forgetfulness of the rule (which you cannot move).

The reason I moved is because my neck was hurting and wanted to relief myself, so my natural response was to move a little bit for relief of my neck, but then I realized that you’re not allowed to move, is such prayer valid?

If you move slightly without actually removing any of the seven parts that are supposed to be on the ground from the ground, you are OK