Connecting Tech Pros Worldwide Forums | Help | Site Map

Prevent duplicate entry

Newbie
 
Join Date: Oct 2007
Posts: 9
#1: Dec 21 '07
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry attempt.

How do I capture that in my PHP page if someone tries to enter duplicate record info?

My PHP Oracle insert statement in the action page:

Expand|Select|Wrap|Line Numbers
  1. $s = OCIParse($c, "insert into tableOne values ('$varOne', '$varTwo', '$varThree')");
  2. OCIExecute($s, OCI_DEFAULT);
How would I capture the ORA-00001 unique constraint message to prevent a duplicate entry into the Oracle table?

Ranjan kumar Barik's Avatar
Member
 
Join Date: Aug 2007
Posts: 95
#2: Dec 21 '07

re: Prevent duplicate entry


Quote:

Originally Posted by chicago1985

I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry attempt.

How do I capture that in my PHP page if someone tries to enter duplicate record info?

My PHP Oracle insert statement in the action page:

Expand|Select|Wrap|Line Numbers
  1. $s = OCIParse($c, "insert into tableOne values ('$varOne', '$varTwo', '$varThree')");
  2. OCIExecute($s, OCI_DEFAULT);
How would I capture the ORA-00001 unique constraint message to prevent a duplicate entry into the Oracle table?

Hi,
You can do one thing.
First get the all the values you have in the respective column.
Then compare it with the inserted value and if there is no matching then execute the insert statement.
else Display an error message to the user.

Happy Programming!
:)
Reply