CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Can't modify database record properly

 



shaunaz
Deleted

Nov 26, 2000, 12:53 PM

Post #1 of 2 (313 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") &#0124; &#0124; 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") &#0124; &#0124; 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;



CuzDesign
Deleted

Nov 27, 2000, 7:45 AM

Post #2 of 2 (313 views)
Re: Can't modify database record properly [In reply to] Can't Post

Hello,
Here is what I use when I am changing the data in a database record.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


# Open database
open(DATA, "<$userspath");
if ($LOCK_EX){
flock(DATA, $LOCK_EX); #Locks the file
}
while(<DATA> ){
(@res)=split(/:/, $_);
# Check to see if the record exsists
if ($res[0] eq "$useremail"){
push(@new, "$newemail:$username:$newpassword:$firstname:$lastname:$company:$address:$city:$state:$zip:$country:$phone\n");
}else{
push(@new,$_);
}
}
close(DATA);


open(NEW_DATA, ">$userspath");
if ($LOCK_EX){
flock(NEW_DATA, $LOCK_EX); #Locks the file
}
print NEW_DATA @new;
close(NEW_DATA);
</pre><HR></BLOCKQUOTE>

Hope this helps.

Regards,
Ray

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives