Most propably because your code it a litle bit complicated
I have a couple of questions
1. Did you wrote the code or did you find it somewhere ? (I am asking this because i think some code is missing)
2. 1 query on each table, also nowhere in your mysql queries you croscheck if the pilot has done the flight you just ask to display
and that is why you have false information showing up