Trying to control motor with Ping ultrasonic sensor

You need to break it down.
Does your sensor give you reasonable values?
You find out by putting a print statement in the code and seeing what values it returns.
Then are your if statements doing the right thing? Again a print statement will tell you what part of the program you are in.
Finally is your hardware working correctly? A print statement will tell you if you have sent the code to make it move.