Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script produced no output

Status
Not open for further replies.

varajan

Technical User
Oct 5, 2001
42
0
0
IN
Hi,

Could someone help me out with this ? I am a novice as far as perl programming is concerned.

The following HTML if invoking the cgi script mentioned below. However, the result is:
'D:\Rajan\cgi-bin\comments.cgi' script produced no output

What is wrong with the script ?

Thanks,
Rajan


HTML

<FORM action=&quot; method=&quot;get&quot;>
Problem Type:
<INPUT type=radio name=probtype value=hardware>hardware
<INPUT type=radio name=probtype value=software>software
<BR>
<TEXTAREA name=problem rows=10 cols=40>
Describe your problem.
</TEXTAREA>
<BR>
Your Name:
<INPUT type=text width=40 name=name><BR>
<INPUT type=submit name=submit value=&quot;Submit Problem&quot;>
</FORM>


CGI Script

#! d:\perl\bin\perl -w

use strict;
use CGI qw:)standard);

my $comment_book = &quot;d:\rajan\comment_book.txt&quot;;

sub save {
open ( CB, &quot;>>$comment_book&quot; ) die &quot;Cannot open $comment_book&quot;;
print CB &quot;Name: &quot;, param('name'), &quot;\n&quot;;
print CB &quot;Problem Type: &quot;, param('probtype'), &quot;\n&quot;;
print CB &quot;Problem Description: &quot;, param('problem'), &quot;\n&quot;;
close (CB);
}

sub display {
open ( CB, &quot;$comment_book&quot; ) die &quot;Cannot open $comment_book&quot;;
while (<CB>) {
print &quot;<B>$_</B><P>&quot;;
my ($type, $prob);
$type = <CB>;
$prob = <CB>;
print &quot;$type<P>&quot;;
print &quot;$prob<BR><HR>&quot;;
}
close (CB);
}

print header;
if (defined param('submit'))
save;
display;
}
 
I'm suprised you don't at least get an error.

Your if statement is missing an open curly-brace. ______________________________________________________________________
Perfection in engineering does not happen when there is nothing more to add.
Rather it happens when there is nothing more to take away.
 
I made the following changes:

From

if (defined param('submit'))
save;
display;
}

To
if (defined param('submit')) {
save;
display;
}

Still it says : 'D:\Rajan\cgi-bin\comments.cgi' script produced no output




 
You should also replace &quot;\&quot; with &quot;\\&quot; in DOS filenames in perl.

If that does not work, try putting in debugging footprints to see what the program does and does not run. ______________________________________________________________________
Perfection in engineering does not happen when there is nothing more to add.
Rather it happens when there is nothing more to take away.
 
I just changed the script to include the following:

#! d:\perl\bin\perl -w

use strict;
use CGI qw:)standard);

print header;
print &quot;The Name was : &quot;, param('name'), &quot;<BR>&quot;;
print &quot;The Problem type was : &quot;, param('probtype'), &quot;<BR>&quot;;
print &quot;The Problem description was : &quot;, param('problem'), &quot;<BR>&quot;;

And now it displays:
The Name was : fdfd
The Problem type was : hardware
The Problem description was : Describe your problem.

So, I guess there is someother way to print a scalar variable. Seems to be working fine for param.
 
Also you need and 'or' between your open() statement and the die() statement.

jaa
 
Sure, I had just abt. observed that, and have included the || between the open and die.

And now it just brings a blank screen, with the following URL

Also, tried to execute the script directly after making necessary changes. Its works that way.

Is there any other way to print the ouput scalar variables in the browser window ?
 
it's not working with the url you're using because you don't define the 'submit' parameter in it. Your script doesn't do anything if 'submit' isn't defined.

jaa
 
You are better using &quot;or&quot; rather than &quot;||&quot; for die clauses. &quot;or&quot; and &quot;and&quot; have lower priorities than &quot;||&quot; and &quot;&&&quot;. If you use &quot;||&quot; you can sometimes end up with difficult-to-debug errors.

param is a function which returns a form variable. It isn't a scalar exactly, though since it returns a scalar, you can treat it as on on the RH side of an operator.

Look at the source of what is on the screen. Is there anything there? ______________________________________________________________________
Perfection in engineering does not happen when there is nothing more to add.
Rather it happens when there is nothing more to take away.
 
I have defined submit, and yet it does not print any thing. I am including both the HTML and Script. Could you let me know if something else is missing ?

HTML

<FORM action=&quot; method=&quot;get&quot;>
Problem Type:
<INPUT type=radio name=probtype value=hardware>hardware
<INPUT type=radio name=probtype value=software>software
<BR>
<TEXTAREA name=problem rows=10 cols=40>
Describe your problem.
</TEXTAREA>
<BR>
Your Name:
<INPUT type=text width=40 name=name><BR>
<INPUT type=&quot;submit&quot; value=&quot;Send&quot;><INPUT type=&quot;reset&quot;>
</FORM>

CGI

#! d:\perl\bin\perl -w

use strict;
use CGI qw:)standard);

my $comment_book = &quot;d:/rajan/comment_book.txt&quot;;

sub save {
open ( CB, &quot;>>$comment_book&quot; ) || die &quot;Cannot open $comment_book&quot;;
print CB &quot;Name: &quot;, param('name'), &quot;\n&quot;;
print CB &quot;Problem Type: &quot;, param('probtype'), &quot;\n&quot;;
print CB &quot;Problem Description: &quot;, param('problem'), &quot;\n&quot;;
close (CB);
}

sub display {
open ( CB, &quot;$comment_book&quot; ) || die &quot;Cannot open $comment_book&quot;;
while (<CB>) {
print &quot;<B>$_</B><P>&quot;;
my ($type, $prob);
$type = <CB>;
$prob = <CB>;
print &quot;$type<P>&quot;;
print &quot;$prob<BR><HR>&quot;;
}
close (CB);
}

print header;
if (defined param('submit')) {
save();
display();
}
 
source just includes the following:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML><HEAD>
<META http-equiv=Content-Type content=&quot;text/html; charset=iso-8859-1&quot;></HEAD>
<BODY></BODY></HTML>
 
Do the values get written to your data file? ______________________________________________________________________
Perfection in engineering does not happen when there is nothing more to add.
Rather it happens when there is nothing more to take away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top