I have searched for almost similar questions but none of those gave me the right answer. I have a fully working file_exist code in if else statement he
You are trying to call a PHP function the same way as a JavaScript function. This just doesn't work.
onclick="readexisting()"
You can only call JavaScript functions like this.