Update scan.php

Moved the PDO prepared statement outside the loop and added logic to check for empty scan arguments.