If you're running this in a loop, you'll get a display for every iteration since $lastname == $lastname will always return true,
same way 5 == 5 will always return true. If, say, $x == 5, that's another story.
Assuming that you have the right equality test in your code, and running it in a loop, insert "break" after your echo statement so that when a match is found, it breaks out of the loop, therefore, displaying your message only once.