Below is my script that I am having troubles with. I have looked it all
over but can not seem to fix the problem. Could somebody look at it
for me and see if my mistake jumps out at them. I am pretty new to
Perl and would be greatful for any help.

Thanks
Stephen


#!/usr/bin/perl -w
use strict;
#use CGI;
use CGI qw(:standard);
use CGI::Carp;
use DBI;

#CGI::use_named_parameters(1);

my ($db,$table,$server,$host);
my $output = new CGI;
#$server = param('server') or $server = 'localhost';
$db = 'invite' ;


#Connection request to server
my $dbh = DBI->connect("DBI:mysql:$db", '<username>', '<mypass>');

# Now to make my query for the server, asking for all data in table.
my $table_data = $dbh->prepare("SELECT * FROM $table");

# Now to send the query to the server
$table_data->execute;

# Checking to see if database is there, if not generate a error response.
if (not $table_data)  {
           print header, start_html ('title'=>"Information on $host => $db => 
$table", 'BGCOLOR'=>'white');

          print <<END_OF_HTML;
<h1>$host</h1>
<h2>$db</h2>
The table '$table' does not exist in $db on $host.
</body></html>
END_OF_HTML
               exit(0);

}



# If we make it to here then we know there is a database with some data for 
us.
# Now we make the table layout for the information.

print header, start_html('title'=>"Information on $host => $db => $table", 
'BGCOLOR'=>'white');
print <<END_OF_HTML;

<h1>$host</h1>
<h2>$db</h2>
<h3>$table</h3>
<p>
<TABLE BORDER>
<caption>Fields</caption>
<tr>
  <th>Field<th>Type<th>Size<th>NOT NULL
</tr>
<ul>
END_OF_HTML

# Gather the information about the table and its fields
my @fields = @{$table_data->NAME};
my @types = @{$table_data->TYPE};
my @not_null = @{$table_data->is-not-null};
my @length = @{$table_data->length};


# Now to display the data

foreach my $field (0..$#fields)  {
              print "<tr>\n";
print "<td>$fields[$field]<td>$types[$field]<td>";
              print $length[$field] if $types[$field] eq 'SQL_CHAR';
              print "<td>";
              print 'y' if ($not_null[$field]);
              print "</tr>\n";

}


print <<END_OF_HTML ;

</table>
<p>
>b?Data</b><br>
<ol>
END_OF_HTML

while(my(@data)=$table_data->fetchrow_array) {
     print "<li>\n<ul>";
     for (0..$#data) {
                print "<li>$fields[$_] => $data[$_]</li>\n";
         }
               print "</ul></li>";
}

print <<END_OF_HTML;
</ol>
</body></html>
END_OF_HTML

Reply via email to