shorye
05-14-2008, 11:29 PM
Hey guys I need your help for the same.
I am a beginner and working on perlCGI, facing following problem
I am fetching data from Database and displaying that into the HTML table format but at the same time I need to provide the facility to add new data in into the database and display that too in HTML table.
Don't know is it possible in PerlCGI.
I am able to do following :-
1) I am able to fetch and display the data.
2) able to insert the Data in DB but not able to show existing data on the same page.
Following is my code:-
print "<html>\n";
print "<head><TITLE>Comment</TITLE></HEAD>\n";
print "<form action=\"comment.cgi\" method=\"POST\">\n";
print "<table valign=top align=center>\n";
print "<tr><td valign=top>\n";
print "<table border=2 cellpadding=3px>\n";
print "<tr><th bgcolor=$color_h1 colspan=7 align=left>Comment</th></tr>\n";
print "<tr><th bgcolor=$color_h2 colspan=1>Date</th><th bgcolor=$color_h2 colspan=1>Server</th><th bgcolor=$color_h2 colspan=1>UserID</th><th bgcolor=$color_h2 colspan=1>BLTest</th><th bgcolor=$color_h2 colspan=1>Comment</th><th bgcolor=$color_h2 colspan=2>Action</th></tr>\n";
print "<tr><td>$curr_date</td><td><input type=\"text\" name=\"node\"></td><td><input type=\"text\" name=\"uid\"></td><td><input type=\"text\" name=\"bltest\"></td><td><input type=\"text\" name=\"comment\"></td><td><input type=\"submit\" value=\"ADD\"></td><td><input type=\"submit\" value=\"DEL\"></td></tr>\n";
print "<tr><td>\n";
my $sql="SELECT * FROM comp_comment";
my $sth=$dbh->prepare($sql) or die "Error: Cannot prepare: ";
$sth->execute() or die "Error: Cannot execute: ";
my $row_count=$sth->rows;
my $comment;
if ($row_count != 0) {
while (my $row=$sth->fetchrow_arrayref){
$comment->{@$row[0]}->{@$row[1]}->{@$row[2]}->{@$row[3]}->{@$row[4]}->{@$row[5]}="";
printf "<tr><td>@$row[5]</td><td>@$row[1]</td><td>@$row[2]</td><td>@$row[3]</td><td>@$row[4]</td></tr>\n";
}
}
print "</table>\n";
print "</td></tr>\n";
print "</table>\n";
print "<hr>\n";
print "</form>\n";
print "</body>\n";
print "</html>\n";
I am a beginner and working on perlCGI, facing following problem
I am fetching data from Database and displaying that into the HTML table format but at the same time I need to provide the facility to add new data in into the database and display that too in HTML table.
Don't know is it possible in PerlCGI.
I am able to do following :-
1) I am able to fetch and display the data.
2) able to insert the Data in DB but not able to show existing data on the same page.
Following is my code:-
print "<html>\n";
print "<head><TITLE>Comment</TITLE></HEAD>\n";
print "<form action=\"comment.cgi\" method=\"POST\">\n";
print "<table valign=top align=center>\n";
print "<tr><td valign=top>\n";
print "<table border=2 cellpadding=3px>\n";
print "<tr><th bgcolor=$color_h1 colspan=7 align=left>Comment</th></tr>\n";
print "<tr><th bgcolor=$color_h2 colspan=1>Date</th><th bgcolor=$color_h2 colspan=1>Server</th><th bgcolor=$color_h2 colspan=1>UserID</th><th bgcolor=$color_h2 colspan=1>BLTest</th><th bgcolor=$color_h2 colspan=1>Comment</th><th bgcolor=$color_h2 colspan=2>Action</th></tr>\n";
print "<tr><td>$curr_date</td><td><input type=\"text\" name=\"node\"></td><td><input type=\"text\" name=\"uid\"></td><td><input type=\"text\" name=\"bltest\"></td><td><input type=\"text\" name=\"comment\"></td><td><input type=\"submit\" value=\"ADD\"></td><td><input type=\"submit\" value=\"DEL\"></td></tr>\n";
print "<tr><td>\n";
my $sql="SELECT * FROM comp_comment";
my $sth=$dbh->prepare($sql) or die "Error: Cannot prepare: ";
$sth->execute() or die "Error: Cannot execute: ";
my $row_count=$sth->rows;
my $comment;
if ($row_count != 0) {
while (my $row=$sth->fetchrow_arrayref){
$comment->{@$row[0]}->{@$row[1]}->{@$row[2]}->{@$row[3]}->{@$row[4]}->{@$row[5]}="";
printf "<tr><td>@$row[5]</td><td>@$row[1]</td><td>@$row[2]</td><td>@$row[3]</td><td>@$row[4]</td></tr>\n";
}
}
print "</table>\n";
print "</td></tr>\n";
print "</table>\n";
print "<hr>\n";
print "</form>\n";
print "</body>\n";
print "</html>\n";