Gossamer Forum
Home : General : Perl Programming :

duplicate entries..... (different approach)

Quote Reply
duplicate entries..... (different approach)
Hi, I need to solve the following problem: duplicate entries!

It's for a form / script that allow users to fill-in their name,adress, education, ....and upload their resume. Because I don't want to open the whole text-database (kind of a modified add.cgi of Links 2.0) for speed and security I'm looking for a different approach. Actually I was thinking of the following, and would like to receive some comments/suggestions: (Maybe there is a better and easier way! Only I didn't see during my searches.)

Convert the whole "%in" to a string or digit, store this digit in a text-file or as a cookie and check this information wehen processing the form.


....the problem is: I don't know if its possible to convert %in into a unique string or digit and how to do it.

Something like........

Code:

# Calculate unique string..
$string = &calculate_string(%in);

# Check for a stored string
$saved = new CGI;
$cookie = $saved->cookie('form_name');

# Let's compare the two strings.
if ($string ne $cookie) { $valid = 1; }
$valid or &site_html_request_duplicate and return;

Code:

Last edited by:

cK: Jun 14, 2002, 8:53 AM
Quote Reply
Re: [cK] duplicate entries..... (different approach) In reply to
>>Because I don't want to open the whole text-database<<

The only reliable way to do it would be to read the database...cookies are unreliable. As long as your code is good then you don't need to worry "too" much.

Use a while loop so that not too much is read into memory and use last if you find a match...that will ensure the code compiles at optimum speed.

eg....

Code:
my $first_field = 0;

open DB, $your_database || die $!;
while (<DB>) {
chomp;
my @line = split/\Q$delimiter\E/;
if ($line[$first_field] eq $some_input) {
we found a match
last;
}
next;
}
close DB;

Last edited by:

Paul: Jun 14, 2002, 9:05 AM
Quote Reply
Re: [Paul] duplicate entries..... (different approach) In reply to
Thanks for the input, I'll give it a try. But as I'm always curious how things work I would still like to know I if its possible to convert %in into a unique string or digit and how to do it.
Quote Reply
Re: [cK] duplicate entries..... (different approach) In reply to
I'm not really sure what you mean?
Quote Reply
Re: [Paul] duplicate entries..... (different approach) In reply to
Ok, then I'll explain a bit more Wink

Let's take the standard add.cgi form Links2.0 as en example. In particular the next piece of code:

Code:
Validate the form input..
$status = &validate_record(%in);

Here all the input of the user (= information he entered in the online form) is send to the sub validate_record. $in contains multiple $in{'Record_Names'}. And know I was wondering if an some way you could give a unique code or a reference to %in ? For example:

If alle the words in %in total would be 345 chars, then with the following sub the value 345 would be set to $string. (But you could alsow use only the a's en b's? Just anything to create a unique id for the form input. Just to make sure that the second input is not equal to the first.)

Code:
$string = %calculate_sting(%in);
sub calculate_string {
# do something here
}
Let me know if its still not clear...........

Last edited by:

cK: Jun 14, 2002, 11:18 AM
Quote Reply
Re: [cK] duplicate entries..... (different approach) In reply to
Ok I see what you mean but I don't think it is a good solution I'm afraid...it would be unreliable ;(
Quote Reply
Re: [Paul] duplicate entries..... (different approach) In reply to
In Reply To:
Ok I see what you mean but I don't think it is a good solution I'm afraid...it would be unreliable ;(

Why, in my opinion it would be much more reliable. Because now you check the input of ALL fields, not just one or two ......

Just imagine, somebody hits the back-button on purpose to edit their Lastname (hé, it just an example....) but the script says 'error: duplicate entry', just based on the same firstname and emailaddress. With my method (does it have a name?) this won't happen.....
Quote Reply
Re: [cK] duplicate entries..... (different approach) In reply to
The most reliable way I can think of is creating an MD5 checksum of all fields.

http://www.perldoc.com/.../lib/Digest/MD5.html

I still don't think its wise but I won't stop you :)

Last edited by:

Paul: Jun 14, 2002, 11:31 AM