I did some research and fiddling and ended up with this:
//mouse_projection is the vector with the coords of where the mouse ray hits the plane
//width is the width of the terrain
//length is the length of the terrain
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(10.0f, 10.0f, 1.0f);
glTranslatef(-(mouse_projection.x + w/2.0f - 1.0f) / w, -(mouse_projection.z + l/2.0f - 1.0f) / l, 0.0f);
glMatrixMode(GL_MODELVIEW);
but this gives me this: (the white dot being where I clicked) The top left has texture coords (0, 0) and the bottom right has texture coords (1, 1).
As you can see the texture is being stretched and darkened, I'm not sure how to prevent this. I think it's something to do with scaling the texture and because of the texture being set to clamp. I'm not sure what to do from here to get it just so there's that square in the middle without any stretching.