Click to See Complete Forum and Search --> : database.....


viZi0n
09-28-2004, 12:01 PM
Can someone check this script out for me? I keep getting internal server error.

#!/usr/bin/perl -wT
use strict;
use CGI;
use DBI;

dbh=DBI->connect($cycbrad, $coaches, $training);



# Display Contents of First Table
$sql = $dbh->prepare("SELECT * FROM $cycid[0]");
$sql->execute;

do {
@data=$sql->fetchrow_array;

# print contents of this record
for each $x (@data) {
print $x . '\t";
}
print "\n";
} while (@data != 0);

$dbh->disconnect;

print "<H2>CYC</H2><HR>";
print $query->end_html();

silent11
09-28-2004, 12:21 PM
I see print $query->end_html();


where is

$query->start_html();



also, shouldn't

dbh=DBI...

be

$bdh=DBI...

CyCo
09-28-2004, 12:28 PM
...and also mismatched string terminators here:


# print contents of this record
for each $x (@data) {
print $x . '\t";
}


should be:


# print contents of this record
for each $x (@data) {
print $x . "\t";
}


one other thing upon further review... I believe the for each statement should be one word foreach

viZi0n
09-28-2004, 02:53 PM
ok this is what i have now and i still get server error.

#!/usr/bin/perl -wT
use strict;
use CGI;
use DBI;

$dbh=DBI->connect($cycbrad, $coaches, $training);



# Display Contents of First Table
$sql = $dbh->prepare("SELECT * FROM $cycid[0]");
$sql->execute;

do {
@data=$sql->fetchrow_array;

print $query->start_html();

# print contents of this record
foreach $x (@data) {
print $x . "\t";
}
print "\n";
} while (@data != 0);

$dbh->disconnect;

print "<H2>CYC</H2><HR>";
print $query->end_html();

CyCo
09-28-2004, 03:44 PM
Since you are using the strict pragma, you need to declare all global variables with "my". Plus, before creating the CGI object, you need to declare that object first.

add this to your code , just below use DBI:



my $query = CGI->new();
my ($dbh, $sql, @data, $x, @cycid, $cycbrad, $coaches, $training);

viZi0n
09-28-2004, 03:53 PM
done....still get server error though

#!/usr/bin/perl -wT
use strict;
use CGI;
use DBI;

$dbh=DBI->connect($cycbrad, $coaches, $training);

my $query = CGI->new();
my ($dbh, $sql, @data, $x, @cycid, $cycbrad, $coaches, $training);

# Display Contents of First Table
$sql = $dbh->prepare("SELECT * FROM $cycid[0]");
$sql->execute;

do {
@data=$sql->fetchrow_array;

print $query->start_html();

# print contents of this record
foreach $x (@data) {
print $x . "\t";
}
print "\n";
} while (@data != 0);

$dbh->disconnect;

print "<H2>CYC</H2><HR>";
print $query->end_html();

CyCo
09-28-2004, 04:00 PM
No, it should be like this:

#!/usr/bin/perl -wT
use strict;
use CGI;
use DBI;

my $query = CGI->new();
my ($dbh, $sql, @data, $x, @cycid, $cycbrad, $coaches, $training);

$dbh=DBI->connect($cycbrad, $coaches, $training);

...rest of script...

viZi0n
09-28-2004, 06:59 PM
now it says page cannot be displayed....i guess im getting somewhere.


#!/usr/bin/perl -wT
use strict;
use CGI;
use DBI;

my $query = CGI->new();
my ($dbh, $sql, @data, $x, @cycid, $cycbrad, $coaches, $training);

$dbh=DBI->connect($cycbrad, $coaches, $training);


# Display Contents of First Table
$sql = $dbh->prepare("SELECT * FROM $cycid[0]");
$sql->execute;

do {
@data=$sql->fetchrow_array;

print $query->start_html();

# print contents of this record
foreach $x (@data) {
print $x . "\t";
}
print "\n";
} while (@data != 0);

$dbh->disconnect;

print "<H2>CYC</H2><HR>";
print $query->end_html();