n_pedido is set as a unique column in your database but you are attempting to insert a value that already exists in the table.
I don't even see an <input> field named "numero" which you are using to do the update. Your trigger for the database insert is "before page load" which runs before any form is posted, so something is wrong with that logic.