Here is what I would do (didnt check this, so sorry if there are errors) :
// UPif(map[player.x / TILESIZE][(player.y - player.p_speed) / TILESIZE] == 0...// DOWNif(map[player.x / TILESIZE][(player.y / TILESIZE) + 1] == 0...// RIGHTif(map[(player.x / TILESIZE) + 1][player.y / TILESIZE] == 0...// LEFTif(map[(player.x - player.p_speed) / TILESIZE][player.y / TILESIZE] == 0...
This is assuming your players starting positiong and speed allows him to exactly touch walls (if not I think it might give some strange results at times). With that I mean, for instance, if your TILESIZE is 32, your players speed should be 1, 2, 4, 8, 16, or 32, and the starting position should be accordingly. TILESIZE = 32, speed = 4, startx = 32, starty = 32 for instance should work with this method. You would probably want that in most cases anyway, so the player sprite wount stop like 5 pixels away from the wall, because its supposed to walk 6.
Cheers.