Can someone look at this for me:
I am trying to set up a script to edit an item in a flat file DB but I don't seem to be getting the data to the Photoedit script. It seems to be reading the 1st line of the DB and not what is selected.
I am all messed up..I know this is straight forward but I am having a real hard time with this.
I am wanting the user to be able to select a photo (nfile_name - radio button) and if desired alter the text cation (ncaption - text box)
here is a portion of the code for the data I am collecting:
[CODE=perl]
#!/usr/bin/perl
$dbp='/home/childcar/db/dbp.txt';
$photopath='htt p://www.myorg.org/toypics/';
print "Content-type: text/html\n\n";
print <<"HTML";
<head><title> </title/><body>
<form action='photoed it.pl' method='GET'>
<input type='hidden' name='nfile_nam e' value='$input{' nfile_name'}'>
<input type='hidden' name='ncaption' value='$input{' ncaption'}'>
<td bgcolor='#F5F5F 5' colspan='6'>
HTML
my $td_start = qq{<td bgcolor='#F5F5F 5' width='145' valign='top' align='center'> };
my $td_start2 = qq{ border='0' width='25' height='25'><br ><INPUT TYPE='radio' NAME='nfile_nam e' value='};
my $td_end = qq{</td>};
my $showpic = q{<table cellpadding='2' border='0' width='729' cellspacing='2' bgcolor='#F5F5F 5'><tr>};
open (BASE, $dbp) or no_open();
my @sorted = sort(<BASE>);
close BASE;
my $i = 0;
foreach my $pair (@sorted){
$i++;
my @show = split(/,/, $pair);
$showpic .= qq{$td_start<in put type='text' name='ncaption' value='$show[1]' maxlength='10' size='15'><br>< img src='$photopath $show[0]'$td_start2$pho topath$show[0]'>$td_end};
if ($i == 5) {
$showpic .= '</tr><tr>';
$i = 0; # <-- reset the flag
}
}
$showpic .= '</tr></table>';
print $showpic;
print<<"HTML";
</body>
HTML
[/CODE]
here is the photoedit.pl script:
[CODE=perl]
#!/usr/bin/perl
$database='/home/childcar/db/dbp.txt';
$databaseview=' http://www.myorg.org/cgi-bin/admintoy/photo.pl';
&parse_form;
open (ORGDB,"<$datab ase");
@ODB=<ORGDB>;
close (ORGDB);
open (DATABASE,">$da tabase");
@DB=<DATABASE>;
foreach $rec (@ODB){
chomp($rec);
($file_name,$ca ption,)=split(/\,/,$rec);
if ($file_name eq $input{'file_na me'} && $caption eq $input{'caption '}){
print DATABASE "$input{'nfile_ name'},$input{' ncaption'},\n";
}else{
print DATABASE "$file_name,$ca ption,\n";
}
}
close (DATABASE);
print "Location: $databaseview\n \n";
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
if (length($buffer ) < 5) {
$buffer = $ENV{QUERY_STRI NG};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($file_name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/,/ /;
$input{$file_na me} = $value;
}
}
[/CODE]
thanks
I am trying to set up a script to edit an item in a flat file DB but I don't seem to be getting the data to the Photoedit script. It seems to be reading the 1st line of the DB and not what is selected.
I am all messed up..I know this is straight forward but I am having a real hard time with this.
I am wanting the user to be able to select a photo (nfile_name - radio button) and if desired alter the text cation (ncaption - text box)
here is a portion of the code for the data I am collecting:
[CODE=perl]
#!/usr/bin/perl
$dbp='/home/childcar/db/dbp.txt';
$photopath='htt p://www.myorg.org/toypics/';
print "Content-type: text/html\n\n";
print <<"HTML";
<head><title> </title/><body>
<form action='photoed it.pl' method='GET'>
<input type='hidden' name='nfile_nam e' value='$input{' nfile_name'}'>
<input type='hidden' name='ncaption' value='$input{' ncaption'}'>
<td bgcolor='#F5F5F 5' colspan='6'>
HTML
my $td_start = qq{<td bgcolor='#F5F5F 5' width='145' valign='top' align='center'> };
my $td_start2 = qq{ border='0' width='25' height='25'><br ><INPUT TYPE='radio' NAME='nfile_nam e' value='};
my $td_end = qq{</td>};
my $showpic = q{<table cellpadding='2' border='0' width='729' cellspacing='2' bgcolor='#F5F5F 5'><tr>};
open (BASE, $dbp) or no_open();
my @sorted = sort(<BASE>);
close BASE;
my $i = 0;
foreach my $pair (@sorted){
$i++;
my @show = split(/,/, $pair);
$showpic .= qq{$td_start<in put type='text' name='ncaption' value='$show[1]' maxlength='10' size='15'><br>< img src='$photopath $show[0]'$td_start2$pho topath$show[0]'>$td_end};
if ($i == 5) {
$showpic .= '</tr><tr>';
$i = 0; # <-- reset the flag
}
}
$showpic .= '</tr></table>';
print $showpic;
print<<"HTML";
</body>
HTML
[/CODE]
here is the photoedit.pl script:
[CODE=perl]
#!/usr/bin/perl
$database='/home/childcar/db/dbp.txt';
$databaseview=' http://www.myorg.org/cgi-bin/admintoy/photo.pl';
&parse_form;
open (ORGDB,"<$datab ase");
@ODB=<ORGDB>;
close (ORGDB);
open (DATABASE,">$da tabase");
@DB=<DATABASE>;
foreach $rec (@ODB){
chomp($rec);
($file_name,$ca ption,)=split(/\,/,$rec);
if ($file_name eq $input{'file_na me'} && $caption eq $input{'caption '}){
print DATABASE "$input{'nfile_ name'},$input{' ncaption'},\n";
}else{
print DATABASE "$file_name,$ca ption,\n";
}
}
close (DATABASE);
print "Location: $databaseview\n \n";
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
if (length($buffer ) < 5) {
$buffer = $ENV{QUERY_STRI NG};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($file_name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/,/ /;
$input{$file_na me} = $value;
}
}
[/CODE]
thanks
Comment