Hi, I have created a page for Signon that is based on a User table in MySQL. One of the fields is Email. In the underlying MySQL there is a unique index defined for the Email column of the User table.
When I create a User in the page with a new email, it creates perfectly. When I try again with the same email (which I do deliberately to check that the error will be caught), I get a 500 notification, but the text of the error reason for the 500 is not displayed.
In Inspect in Chrome, the problem is clearly indicated.
How do I get the MySQL error to be displayed in an Alert or some such, so that the user has a clue as to what to do about the error that has been caused.
I realize that this error is easily trapped with a Exists validation, so this question is just used as an example of how to handle unanticipated errors from MySQL.
Hi
I could not find any tutorials on try/catch, must be me, they gotta be there somewhere.
I believe it is the âinsertâ step that generates the error when there is an attempt to add a duplicate,
Anyway here us my server connect routine. Where do I add in the âerrorâ dynamic event and how do I get the error into a client side Alert? (if that is how it is done)
Hi TimD Most helpful. You have stored the error message into the database, which is useful for a batch process like your example, but in an online context how do you display the error to the user in a timely manner? Fred refers to a dynamic $_ERROR, but I am not sure how to use it to âtoggle outputâ. What do you think that means?
Hi Fred, I am following your hints, in in my server connect i haveâŚ
When I do this the 500 error disappears from my form when I save, in fact the form achieves a status if âSuccessfulâ, even though I know the insert in the above flow has not worked (because I have deberately made it try to save a duplicate email)
So the question remains, how do I manage the error variable above to be displayed to the user.
I tried a strategy of creating a error variable in the Input POSTs and using that in an Alert in the Success event of the form, but that did not work.
Sorry I did not quite get your original issue. I can suggest this instead, but that means you create the error message from scratch, you donât fetch the SQL message:
Hi Fred, no problem, its a journey alright. I really like the discussion and teh swapping of ideas.
Anyway, the original question was to trap unexpected errors. I did have the validate originally, such as your last suggestion, that is great for trapping the expected error of avoiding duplicates.
Anyway, the good news is that I did find the answer. It is to force an invalid status back to the form then all the error variables liven up with something useful. Check this out.
Yep, I did see that one and it had a couple of clues. Along with more clues from you and Fred it has been a happy ending. Now I just have to put this answer thru all my pages.