You should check for collision after placing the sprite, not before. The collision is checked at the current position of the sprite (which is set by the dbSprite command), so if you check before moving it, you don't know if it will collide after you move it. Also, I don't see the reason for your "moved" variable, it does not change the behaviour of the program.
Try this code. Not tested, but it should work. First, declare two variables (int oldx, int oldy) before the main loop, to store the current position of the sprite. Then, store the coordinates of the sprite, move it, check for collision and if it collides, place it back to the previous position.
// Store current position of sprite.
oldx = posx;
oldy = posy;
//up
if (dbUpKey()) posy -= 1;
//down
if(dbDownKey()) posy += 1;
//right
if (dbRightKey()) posx += 1;
//left
if (dbLeftKey()) posx -= 1;
// Place the sprite at its new position.
// If it collides, go back to previous position.
dbSprite ( 2, posx, posy, 2 );
if (dbSpriteCollision(2,3) ==1) {
posx = oldx;
posy = oldy;
dbSprite ( 2, posx, posy, 2 );
}
// update the screen
dbSync();
dbWait(50);
The dbWait command is not a great way to time a program. It passes for a first attempt but in the future you should use a proper timer. And "go true" should be spelled as "go through".