I tested the network with the training data and the accuracy was 89%.
when I test it after training, the accuracy is 10%
Have you shuffled your training dataset? Since there are 10 target classes (digits 0-9) you should have an equal distribution of all the digits in your training dataset.
If you miss this, the neural network model will not be evenly trained for recognizing all digits, and it will only perform well for the digits it has seen during training.
A small sample size may also lead to a high training accuracy and low test accuracy situation. Ideally, you would like your model to see the variations in the handwritten datasets, the more variation it sees, the better it will be adapted when being tested. You can try to increase your training dataset size to improve this.