The exact same thing happens when you're selling as well.
If you sell a share at $2.99, and then somebody buys at $2.99, then guess what? You still sold it at the price you asked for.
Likewise, if you place a bid for a share at $3 and then you buy at $3, then guess what? You still bought it for the price you asked for.
By the way, that quote in your signature is not only horribly misquoted, but it's horribly written English as well. Ben Franklin wouldn't have written such bad English, ("they who can"? Seriously?) and it was actually written like this:
"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety."
And it likely doesn't mean what you think it means: