Your loop is running very fast.
So the analogWrite() function is called repeatedly very fast, it should be called just once.
You can start to add a delay of 1 second: "delay(1000);" in your loop, just for testing purposes.
After that you should test for a change of the input. Perhaps you might even need a debouce.
If it doesn't work, make small pieces to find the problem.
Try switching a led (perhaps you have a 'uno', a led is at pin 13) according to the input.
Try turning the motor forward backward with delays.
If those are okay, connect them toghether can let the input change the direction and speed.