I have a couple of observations/suggestions that might help.
-
You should use the GET method instead of the POST for the search form, so that you can use the POST method in your update form.
-
Update query should not be the part of the loop that is generating the update form. I recommend moving the update code to the top of the file and put it under the condition of available core fields.
-
There is no field with p_id name in your update form, so include a hidden field for that and update the database based on that field’s value.
-
Also make sure all the generated markup appears in the body tag.
Hopefully, you will have a much better code structure after making these changes and you will also be able to nail down any remaining issues.
Good luck