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:
Displaying selected data from dbase

 



Rab
Deleted

Aug 3, 2000, 3:32 AM

Post #1 of 2 (390 views)
Displaying selected data from dbase Can't Post

Hi Experts....
I am pulling info from a dbase by month -- no probs there Smile
The results are displayed in a table with a check-box at the end of the row to give the user an option to add selected entries to another dbase.
If I omit the check-boxes all works fine...but I'm struggling when I do include them ......

sample code .....


#!/usr/bin/perl

print "Content-type:text/html\n\n";

print "<html><head><title>Update E-mail Dbase</title></head>\n";
print "<body>\n";

$tickedcount = 0;

$filename = "db";

# email database variable
$emaildb = "email.dat";

# empty the temp email dbase before writing to it
&cleardb;

open(INF,$filename)
&#0124; &#0124; die "Can't open the database : $!";

@indata = <INF>;

close(INF);

foreach $i (@indata) {
chop($i);

($password,$date,$inact,$companyname,$date2,$companyname,$inact1,$inact2,
$description,$postcodes,$address,$country,$phone,$phone2,$email,$url) = split(/\_/,$i);

($recordid) = split(/\|/,$i);

$snapcounttotal++;


# this formats date from 2000/07/25 to 25/07/2000 in table at bottom
($snapyear, $snapmonth, $snapday) = split (/\//, $date);

### display by selected month ##########

if ($snapmonth =~ /01/ig) {

####### check-box code ######

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

@checked = ("selected");
foreach $x (@checked) {
if ($FORM{$x} == 1) {
$tickedcount++;
&add_email;

print "u picked $x!\n";
}

die;

}

###### end check box code ###
}

}

print "<HTML><HEAD></HEAD><BODY BGCOLOR=\"C0C0C0\">";
print "<h4 align='center'>Confirmed ! - $tickedcount entries above have been added to the E-mail database </h4>";

############## sub-routines ##########################################
sub add_email {

open (FILE,">>$emaildb") &#0124; &#0124; die "cannot open e-mail file :$!";

print FILE "$email\n";

}

sub cleardb {

open (FILE,">$emaildb") &#0124; &#0124; die "cannot open e-mail file :$!";

print FILE "";

}
########### end sub-routines ########################################


If I tick any of the boxes I get ALL the entries being added not the required Selected (ticked) ones ......

What am I missing guys !

Mike


perlkid
stranger

Aug 3, 2000, 6:50 PM

Post #2 of 2 (390 views)
Re: Displaying selected data from dbase [In reply to] Can't Post

 
Hello Rab,

I have the code to do what you want, It uses the count++; function. What it does is prints the check box with the line number for that result in the check box name. Then after you submit the checked boxes it matches the line numbers back up with the ones you choose. Then it takes them out of the data base they were in and moves them to another one.

But I know If I post the code here when you go to copy and paste it onto your file it will be messy and probably give you an error.

So email me and I'll mail you the file with the code.

tony@olbis.com

perlkid

 
 


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

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