
shaunaz
Deleted
Nov 26, 2000, 12:53 PM
Post #1 of 2
(204 views)
|
|
Can't modify database record properly
|
Can't Post
|
|
Hi, below is a script from which I am trying to use to modify a flatfile database record and cannot seem to access the subscript correctly. Any suggestions? #!/usr/bin/perl require "config.cgi"; use CGI qw(:standard); use CGI::Carp (fatalsToBrowser); # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g; $FORM{$name} = $value; } $id=$ENV{'QUERY_STRING'}; $id=lc($id); $id=$FORM{'id'}; open(MEMBFILE, "$memberfile") | | die "I can't open $memberfile"; @allmembers=<MEMBFILE>; close (MEMBFILE); #browse members for matching member reccord foreach $line (@allmembers){ ($idfile,$name,$email,$address,$city,$state,$zip,$country,$siteurl,$passwordfile,$payments,$weekly,$total,$paidout)=split (/\|/,$line); chomp($payments,$weekly,$total,$paidout); $idfile=lc($idfile); if ($id =~/$idfile\b/ and $password =~/$passwordfile\b/) { &processclick; } #end if } #end foreach print "Location: $FORM{'URL'}\nURI: $FORM{'URL'}\n\n" ; exit; sub processclick { #ADD CLICKS $weekly += $FORM{'LINK'}; $payments += $FORM{'LINK'}; open(MEMBFILE, ">$memberfile") | | die "I can't open $memberfile"; &lock; foreach $line (@allmembers){ ($idfile1,$name1,$email1,$address1,$city1,$state1,$zip1,$country1,$siteurl1,$passwordfile1,$payments1,$weekly1,$total1,$paidout1)=split (/\|/,$line); $idfile1=lc($idfile1); chomp($payments1,$weekly1,$total1,$paidout1); #save new member data if ($id eq $idfile1) { print MEMBFILE "$id|$name|$email|$address|$city|$state|$zip|$country|$siteurl|$password|$payments|$weekly|$total|$paidout\n"; }else{ print MEMBFILE "$idfile1|$name1|$email1|$address1|$city1|$state1|$zip1|$country1|$siteurl1|$passwordfile1|$payments1|$weekly1|$total1|$paidout1\n"; } #end if } #end foreach #finally redirects to the URL print "Location: $FORM{'URL'}\nURI: $FORM{'URL'}\n\n" ; } #end sub sub lock { flock (FILE, 2); seek(FILE, 0, 2); } ############################################## # Sub: File Lock # This locks files when bidding takes place sub lock { flock (FILE, 2); seek(FILE, 0, 2); } ############################################## exit;
|