Neural Network Backpropagation problems
Some reasons the network may not be getting better: 


Learning rate is too high (jumps back and forth forever)
Learning rate is too low (when divided by training set size, goes to zero)
You're replacing the error signal with the weight gradient signal.  The reuse of error (based on the indentation) seems to be right on the same line as the inner loop.  I'm not sure if that's correct.  First, backprop your errors, THEN calculate the gradient based on the activation of the hidden neurons and delta sigmoid(error).