Skip to content
Advertisement

How to show PHP Duplicate Entry error message on current page

I am creating a signup form for a website I am developing. I am using PHP to insert the form into my database. I have the useremail set as a Unique Key in my database. When I type in an email that already exists in my database it brings me to a blank page with this

error message: Duplicate entry ” for key ’email_2′

How can I get this message to show up above the form, without clearing the form? In the code the “SERVER ERROR” and “BOTH FIELDS MUST BE COMPLETE” text is showing up in the correct place. How can I make the Duplicate entry error show up in the same way?

Here is the PHP code I currently have. Please note I am successfully connecting to my database, but did not include the code here.

JavaScript

Here is the Form Code:

JavaScript

Advertisement

Answer

You must run check query before inserting data.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement