student has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone! I have a question regarding the following script. I am having problems getting the first elsif to redirect to another .cgi script. I have found out it is due to the printing of content type of text and html at the top of the script, but I need it to print out the table near that beginning of the script. Any help would be appreciated.
#!/usr/bin/perl print "Content-type: text/html\n\n"; use CGI qw(:standard -debug); use strict; use DBI; #declare variables my ($key, @sysletter, $systems, $dbh, $dsn); my $row = param('row'); my $action = param('action'); my $value = param('value'); #assign initialization string username and password to variables my $dsn = "DBI:mysql:IST221"; my $user_name = "ist221student"; my $password = "password"; my $dbh = DBI->connect($dsn, $user_name, $password); #preparing and executing the statement. if ($action eq "v") { my $sth = $dbh ->prepare("SELECT * FROM products order by pname"); $sth->execute(); print "<HTML><FONT SIZE=15>\n"; print "<BODY><CENTER>\n"; print qq(<table width="70%" border="0" cellspacing="5" align="center"> +<tr><th>Product<th>U/I<th>Quantiy<th>Cost</tr>); while (my @row = $sth -> fetchrow_array()) { print qq(<tr><td>$row[1]<td align=center>$row[2] <td align=center>$row +[3]); printf "<td align=right>%.2f</tr><p>",$row[4]; } } elsif ($action eq "a") { print "Location: http://carrotcake.nsm.tridenttech.edu/tablefunction.c +gi\n\n"; } elsif ($action eq "u") { print "this is the update page under construction\n"; } elsif ($action eq "d") { print "this is the delete page under construction\n"; } else { print "Error!\n"; } print qq (</table>); print "<HTML><FONT SIZE=3>\n"; print "<A HREF='http://carrotcake.nsm.tridenttech.edu/dbhome.html'>\n" +; print "Return to Selection Page"; print "</HTML></FONT>\n";

Replies are listed 'Best First'.
Re: Redirection question
by PodMaster (Abbot) on Nov 21, 2004 at 03:12 UTC
    I am having problems getting the first elsif to redirect to another .cgi script. I have found out it is due to the printing of content type of text and html at the top of the script, but I need it to print out the table near that beginning of the script. Any help would be appreciated.
    What does printing a table have to do with http headers? Many already answered this question the first time you asked it at HTTP headers and redirection. Tutorials also has a very good introduction by Ovid which covers HTTP/CGI.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Redirection question
by duff (Parson) on Nov 21, 2004 at 03:19 UTC

    If you are redirecting, then you aren't printing out any table. Only output the Content-type: header when you need to (i.e., when you're printing the table)

Re: Redirection question
by nedals (Deacon) on Nov 21, 2004 at 08:18 UTC
    Student:
    You asked about this before here HTTP headers and redirection
    Did you read and understand the many responses?

    Read through the last comments (mine) and it will give you some ideas how to solve this problem now and into the future

    EDIT:
    Reading the thread more carefully, I see PodMaster has already had a go at you :-). Please ignore this!
Re: Redirection question
by chanio (Priest) on Nov 21, 2004 at 22:43 UTC
    You mention CGI.pm at your code. Reading it's POD section perldoc CGI is worth it's effort for all your needs. If you use all its power you are able to redirect, create your forms, mark errors, use cookies, etc. At least, invest your time in reading one of the best CGI modules.

    .{\('v')/}
    _`(___)' __________________________
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.