What do you do when this happens?

Asked

Viewed 49 times

-2

I am working on a system in which I must register several data from a form in different tables using mysql. It works like this: The person makes a registration and in the same form requests a special service, I save his data normally and with his ID, which is generated by auto-increment, I save the request data [id, user_id, request,...]. If everything goes right, fine. But the point is, and if the order registration is wrong? Should I delete the user, give the error message and return to the register to register again? What’s the best way out of this?

  • 1

    I think you should consider what might go wrong and work so that the error doesn’t happen and direct the user to the missing point to get ok

  • 2

    The ideal is that all this is in a transaction, so if you fail a rollback, nothing will be done. The second question is to investigate what caused the problem, so register in the logs as many details as possible, if using external services (Newrelic) use them also to investigate what happened. Once the error occurred normally the resend user does not resolve.

1 answer

1

Well, let me get this straight... you receive data from an example form: name,Cpf, request, category in case you want to save name and Cpf in a table and request and category in another correct?

then:

Name saved,Cpf in Tabela1

checking if the id of Tabela1 was generated if generated, takes this id

and use to save the request, category in table2

in case of error when saving in table2 the correct would be to delete the line of Tabela1 where id is what you took and then show a message to the customer saying that there was a problem in the register and that he should try again.

hope I’ve helped!!!

  • Thank you for the answer. That’s exactly what I did, but I found it kind of "gambiarra" to do so... I thought there might be another way, but I guess I’ll just have to leave it at that.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.