Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate record entry

Status
Not open for further replies.

oaklanders

Technical User
Dec 9, 2007
38
I have my PHP inserting into Oracle 9i.
But how do I prevent duplicate record entries?

I only have 3 fields in the insert in the action page:
Code:
<?php
$c=OCILogon("scott", "tiger", "orcl");
  if ( ! $c ) {
    echo "Unable to connect: " . var_dump( OCIError() );
    die();
  }

$s = OCIParse($c, "INSERT INTO personTable (firstname,lastname,emailaddress) VALUES ($_POST[firstname],'$_POST[lastname]','$_POST[emailaddress]'");
OCIExecute($s, OCI_DEFAULT);
echo "Record successfully entered";
?>

How do I prevent duplicate record info and show the user they entered duplicate info.
 
Depending on what you would consider a duplicate entry, you would probably have to create a query with whatever they entered, if it brings back results then its probably duplicated, and you don't perform and insert.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, my attempt doesnt output anything or insert anything even if not a duplicate:

Code:
<?php
$c=OCILogon("scott", "tiger", "orcl");
  if ( ! $c ) {
    echo "Unable to connect: " . var_dump( OCIError() );
    die();
  }
$mydupcheck = "select * from personTable where firstname = $_POST[firstname] and lastname = $_POST[lastname] and emailaddress = $_POST[emailaddress]";

if($mydupcheck)
{
   echo "Duplicate entry";
}
else
{
$s = OCIParse($c, "INSERT INTO personTable (firstname,lastname,emailaddress) VALUES ($_POST[firstname],'$_POST[lastname]','$_POST[emailaddress]'");
OCIExecute($s, OCI_DEFAULT);
echo "Record successfully entered";
}
?>

Please advise.
 
Nowhere are you actually running the query. You re just assigning the string to the variable. I suspect you have to run it like your insert using the OCIParse function there.


Then check for returned results. I'm not very familiar with the PHP functions for ORACLE. but check in PHP's online manual for how to check for records.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
not a php response but does Oracle support the 'REPLACE' syntax? that could also be a solution
 
I would set up a unique key of the fields that should be unique and use "on duplicate key update ...".

In this case, it would be text keys which sucks, but still an option.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top