You could, assuming W8 will run on your machine (it probably will). You could reinstall XP if you’ve got the discs, alternatively. Did your machine come with something akin to a ‘rescue disc’?
There’s two types of hard disk(*). The older IDE disks use a 2″ wide ribbon data cable, modern SATA disks use a much thinner cable about half an inch across. You’ll need to match up the correct interface. Other than that, they’re all much of a muchness.
If it’s an IDE drive, you might get lucky and find that removing and refitting the cable is enough to bring it back to life. Make sure the power’s off though, or you’ll blow the controller.
(* – there’s more, but for all practical purposes this is what you need to know)