Except you fail to do any error checking either so you are not going to find the problem.
Nov 19, 2001, 5:16 AM
Veteran (19537 posts)
Nov 19, 2001, 5:16 AM
Post #27 of 31
Views: 4573
Try this Jeremy:
use CGI qw(:standard);
print "Content-type: text/html\n\n";
require "shopconfig.cgi";
use DBI;
my $dbh = DBI->connect("DBI:mysql:crashint_test:localhost","crashint", "PASSWORD") or &error($DBI::errstr);
my @count = ();
opendir (DR,"$datapath/members/") or &error($!);
@count = grep { /\.txt$/ } readdir(DR);
closedir (DR);
foreach $line (@count) {
print "$line<br>";
open(LIST, "<$datapath/members/$line") or &error($!);
while(<LIST>) {
@data = split /\|/;
my $sth = $dbh->prepare("INSERT INTO foo VALUES ('$data[0]','$data[1]' ...etc)") or &error($DBI::errstr);
$sth->execute;
$sth->finish;
}
}
$dbh->disconnect();
sub error {
print shift;
exit;
}
Code:
#!/usr/bin/perl use CGI qw(:standard);
print "Content-type: text/html\n\n";
require "shopconfig.cgi";
use DBI;
my $dbh = DBI->connect("DBI:mysql:crashint_test:localhost","crashint", "PASSWORD") or &error($DBI::errstr);
my @count = ();
opendir (DR,"$datapath/members/") or &error($!);
@count = grep { /\.txt$/ } readdir(DR);
closedir (DR);
foreach $line (@count) {
print "$line<br>";
open(LIST, "<$datapath/members/$line") or &error($!);
while(<LIST>) {
@data = split /\|/;
my $sth = $dbh->prepare("INSERT INTO foo VALUES ('$data[0]','$data[1]' ...etc)") or &error($DBI::errstr);
$sth->execute;
$sth->finish;
}
}
$dbh->disconnect();
sub error {
print shift;
exit;
}
Nov 19, 2001, 12:23 PM
User (200 posts)
Nov 19, 2001, 12:23 PM
Post #29 of 31
Views: 4489
I did use error checking but nothing showed.
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
Nov 19, 2001, 1:16 PM
Veteran (1936 posts)
Nov 19, 2001, 1:16 PM
Post #30 of 31
Views: 4433
I think you said you already tried only printing to the screen, but try it again...
while (my $file = readdir(DB)) {
next unless $file =~ /\.txt$/;
open (FILE, "C:/data/$file") or die "can't open $file! $!";
print "$file\n" . ("*" x 20) . "\n", <FILE>;
close (FILE);
print "\n\n";
}
closedir (DB);
I'm thinking that if there is no problem printing to the screen, then there is definately a problem with your SQL somewhere.
--Philip
Links 2.0 moderator
Code:
opendir (DB, "C:/data") or die $!; while (my $file = readdir(DB)) {
next unless $file =~ /\.txt$/;
open (FILE, "C:/data/$file") or die "can't open $file! $!";
print "$file\n" . ("*" x 20) . "\n", <FILE>;
close (FILE);
print "\n\n";
}
closedir (DB);
I'm thinking that if there is no problem printing to the screen, then there is definately a problem with your SQL somewhere.
--Philip
Links 2.0 moderator
Last edited by:
ThatPerson1024: Nov 19, 2001, 2:05 PM
Nov 22, 2001, 4:56 AM
User (200 posts)
Nov 22, 2001, 4:56 AM
Post #31 of 31
Views: 4376
Thanks everyone. After I got time to test, I have got it to work with all your help..
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central