Max pid = 10000

The answer to the problem is when the database was originally created. The pid column was set as a varchar(20). So, MAX() will only return 10000 for a varchar column. The solution was to this command.

 ALTER TABLE `patient_data` CHANGE `pid` `pid` BIGINT(50) NULL DEFAULT NULL;

Now, I have reverted the code back to the original and it works as intended.