Gossamer Forum
Home : Products : DBMan : Customization :

db key plus another field unique

Quote Reply
db key plus another field unique
Can someone suggest how I might validate a new record not only by the key, but also by another field? In this case, I'd like there to be only one record per e-mail address as well as only one per user. (One record per user name currently works fine, but it's still possible for someone to create a second record with a new user name. Having a unique e-mail requirement is intended to provide one more small barrier to this.)
Thanks.

Quote Reply
Re: db key plus another field unique In reply to
Thead reference:
http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/002388.html

JPDeni - posted March 27, 2000 08:40 AM PST
---------------------------------------------------------------------

You can check another field for duplicates by adding the bolded lines to
sub validate_record in the db.cgi script: code:

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[number of second field] eq $in{'name of second field'}) {
return "duplicate entry";
}
}

You may want to change "duplicate entry" to something more descriptive of what your situation is.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: db key plus another field unique In reply to
LoisC too fast Smile


Ok, in db.cgi in the sub-routine validate_record, find the section that reads:
Code:

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";
}
close DB;
Now add the following red code:
Code:

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[#] eq $in{'email'}) {
return "duplicate email error";
}

close DB;
Take notes of the two sections in bold:
- Change "#" to the field number of your email field
- Change "email" to the name of your email field

Good luck!

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/