•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,530 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,671 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 808 | Replies: 4
![]() |
•
•
Join Date: Nov 2007
Posts: 22
Reputation:
Rep Power: 1
Solved Threads: 0
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 and my below attempt doesnt output anything or insert anything even if not a duplicate:
How do I prevent duplicate record info and show the user they entered duplicate info.
But how do I prevent duplicate record entries?
I only have 3 fields in the insert in the action page and my below attempt doesnt output anything or insert anything even if not a duplicate:
php Syntax (Toggle Plain Text)
<?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"; } ?>
How do I prevent duplicate record info and show the user they entered duplicate info.
•
•
Join Date: Dec 2007
Posts: 75
Reputation:
Rep Power: 1
Solved Threads: 10
The best approach is to have the DB enforce Referenctial Integrity. Basically you instruct the database at design time NOT to allow duplicates for certain records ever. IF such an attempt is made, the db server will not carry out the operation. Look at these:
http://www.google.com/search?hl=en&c...Oracle&spell=1
http://www.google.com/search?hl=en&c...Oracle&spell=1
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 238
•
•
•
•
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 and my below attempt doesnt output anything or insert anything even if not a duplicate:
There are some errors in your script.
$mydupcheck = "select * from personTable where firstname = $_POST[firstname] and lastname = $_POST[lastname] and emailaddress = $_POST[emailaddress]"; Since firstname, lastname and emailaddress are strings, you should put them in quotes. And btw, you are not executing that query.
•
•
•
•
if($mydupcheck)
{
echo "Duplicate entry";
}
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Dec 2007
Posts: 75
Reputation:
Rep Power: 1
Solved Threads: 10
Try this:
<?php
$c=OCILogon("scott", "tiger", "orcl");
if ( ! $c ) {
echo "Unable to connect: " . var_dump( OCIError() );
die();
}
$sqlString = "select * from personTable where firstname='" . $_POST['firstname'] . "' and lastname='" . $_POST['lastname'] . "' and emailaddress='" . $_POST['emailaddress'] ."'");
$mydupcheck = OCIParse($c, $sqlString);
OCIExecute($mydupcheck);
$nrows = oci_fetch_all($mydupcheck, $results, 0, 1);
if($nrows)
{
echo "Duplicate entry";
}
else
{
$sqlString="INSERT INTO personTable (firstname,lastname,emailaddress) VALUES ('" . $_POST['firstname'] . "','" . $_POST['lastname'] . "','" . $_POST['emailaddress'] . "'";
$s = OCIParse($c, $sqlString);
OCIExecute($s, OCI_DEFAULT);
echo "Record successfully entered";
}
?>![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- Prblem with removing duplicates entries in a list. (Pascal and Delphi)
- Visual Basic coding for excel database - am tearing my hair out! (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: hi
- Next Thread: paging related



Linear Mode