Before you buy the car you must go to the town hall with your passport, original nie certificate and house deeds(escritura).
They will then issue you within 3 days 2 certificado de empadronamiento
1st states it is for the tramitar residencia
2nd states it is for jefatura provincial de trafico
take this to the seller with your nie as he needs them for registration.
You will see that 2nd hand car prices in spain are very expensive.
Be careful if you buy privately as you will be liable for any outstanding debt on the card icluding fines.
Safer to buy through a recognised dealer with a warranty or new.
If you live in spain and bring a car over from another country then by law you must register this in spain after 6 months max.