Use of PID to get the required RPM.

will you please tell me that if my code written is correct

No, that is not possible. We don't have your motor/encoder/setup to test it. That is your job.

However, I have already pointed out an error. Have you corrected it?

Finally, it is a mistake to repeatedly use attachInterrupt() and detachInterrupt(). There is no need at all to use detachInterrupt().