Gossamer Forum
Home : Products : DBMan : Installation :

Check for duplicate records...

Quote Reply
Check for duplicate records...
I wonder, what must I do to let the script check, if the record that some user adds, already was added before, JPD wrote a beautiful mod for me, which gives a user a maximum number of records to add. I think, that there must be some rules added to, to make this checking part works...

Thanks in advance.

Greetings,
-------
Mart.
Quote Reply
Re: Check for duplicate records... In reply to
So if any entry in any one of 8 fields matched the entry in that field in any other record in your database, you would consider it a duplicate record?


------------------
JPD





Quote Reply
Re: Check for duplicate records... In reply to
How many fields do you want to check?


------------------
JPD





Quote Reply
Re: Check for duplicate records... In reply to
If its possible and don't slow down the script, I think about 8???
Quote Reply
Re: Check for duplicate records... In reply to
No, its just that a user not added the same record twice. So lets say, the field nr. 17 (Userid), field nr.2 (Date), nr. 1 (Merk), nr.3 (Model), nr.5 (Year) and nr. 14 (Price). If all this fields maches the added record, its a duplicate record. The user must be able to add his maximum number of records at one time. OK??

Thanks in adv.
--------
Mart.
Quote Reply
Re: Check for duplicate records... In reply to
I'll have to think about it for a bit.


------------------
JPD





Quote Reply
Re: Check for duplicate records... In reply to
In db.cgi, sub validate_record, after

Code:
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
}

add

Code:
unless ($data[field 1 position] eq $in{'field 1 name'}) {
next LINE;
}
unless ($data[field 2 position] eq $in{'field 2 name'}) {
next LINE;
}
unless ($data[field 3 position] eq $in{'field 3 name'}) {
next LINE;
}
unless ($data[field 4 position] eq $in{'field 4 name'}) {
next LINE;
}
unless ($data[field 5 position] eq $in{'field 5 name'}) {
next LINE;
}
unless ($data[field 6 position] eq $in{'field 6 name'}) {
next LINE;
}
unless ($data[field 7 position] eq $in{'field 7 name'}) {
next LINE;
}
if ($data[field 8 position] eq $in{'field 8 name'}) {
return "duplicate record error";;
}

Just be sure to match the field positions with the field names. Seems like it will work, but I won't guarantee it.


------------------
JPD







[This message has been edited by JPDeni (edited July 28, 1999).]
Quote Reply
Re: Check for duplicate records... In reply to
Works great, Smile
Thanks...
Quote Reply
Re: Check for duplicate records... In reply to
Yes, I did that but then doesn't work the max.adding records-mod not, the duplicate record mod works good than.
Quote Reply
Re: Check for duplicate records... In reply to
Okay. I see why.

Move

Code:
if ($data[$auth_user_field] eq $db_userid) {
++$count;
}

so it's just after

Code:
@data = &split_decode($line);

That should do it.


------------------
JPD





Quote Reply
Re: Check for duplicate records... In reply to
Not so great after all..
It do not goes together with the 'maximum adding records' modification, I've tried to implant it elsewhere in the sub 'validate records', but without succes. I post a part of my sub 'validate_records' here:
Code:
my ($col, @input_err, $errstr, $err, $line, @lines, @data);

if ($in{'add_record'}) { # don't need to worry about duplicate key if modifying
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_;
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
}
if ($data[$auth_user_field] eq $db_userid) {
++$count;
}
}
close DB;

if ($count >= $db_maximum_records) {
return "U heeft het maximum aantal records voor elke gebruiker reeds toegevoegd";
}
}

foreach $col (@db_cols) {
(rest of code)
When I use both mod's, I get an error, when the record is not a duplicate, the errormessage is, that "it could not find the label for 'NEXT line'".
Is there a way, to fix them both???

[This message has been edited by mart (edited August 18, 1999).]
Quote Reply
Re: Check for duplicate records... In reply to
Did you place the code I gave you on 28 Jul between

Code:
if ($data[$db_key_pos] eq $in{$db_key}) {
return "duplicate key error";
}

and

Code:
if ($data[$auth_user_field] eq $db_userid) {



------------------
JPD





Quote Reply
Re: Check for duplicate records... In reply to
OK,
I've doublechecked everything and it works.

Thank you...
------
Mart.
Quote Reply
Re: Check for duplicate records... In reply to
This work perfectly now...thanks so much for your time and patience

Can I change my password to something more reasonable? Smile