You allow the player to move before checking for collision.
You should (pseudo)...
do
Check input from player
Check if this would cause a collision
Collision = true then don't move player.
Collision = false then move player.
Display player
loop
You should (pseudo)...
do
Check input from player
Check if this would cause a collision
Collision = true then don't move player.
Collision = false then move player.
Display player
loop