Originally Posted by lld
I have a page that lets the user to add record into the database. After the user clicks on the 'submit' button, I would like to perform a check for duplicate record in my database. (I suppose this is to be done in PHP?).
I would approach this functionality with something like this:
1) User fills out all inputs in a form
3) If they are all valid, send an ajax request to the server to query the database for a duplicate record. The ajax function returns a value of true or false depending on whether thre is a duplicate record.
5) If a duplicate record exists, display a prompt asking the user to confirm if they want to replace the existing record with their new data inputed in the form.
7) If the user chooses to not replace the old record with the new data, then simply return false to the onsubmit event handler which will abort the form submission.
Whether the user submits a new record or chooses to overwrite an existing record, all the <form> data must be validated on the server because the js validation can be easily bypassed and a malicious user could send bogus data to the server side php script without having used your form at all.