Solved

CGI does not work properly

Posted on 1997-08-19
4
165 Views
Last Modified: 2013-12-25
Hi, I am very new to Perl and HTML. I am currently creating a guestbook using html. If the user clicked on the submit button, I will called my perl file to check whether they have entered all the necessary fields.

If the form is not complete, I will then display another redopage html informing them.

But my redopage html does not get shown up. Is it possible for the perl to open up another html???

Below is my perl file which only consists of the calling part, but still the html does not get showed up. Did I miss out any library??? I am actually running it in Windows NT.

/*** my *.pl file ***/

use CGI;

$redopage="/olticket/jonr&d/redopage.html";
$redo;

sub redo
{
      print (REDOPAGE $redopage);
      while (<REDOPAGE>)
      {
           print $_;
      }
      Close(REDOPAGE);
      exit;
}
Could anyone please help.

Thank you.

Regards
Yann Ming
0
Comment
Question by:ymlew
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
icd earned 100 total points
ID: 1829729
The problem is that you are not opening the file. Try:-

sub redo
{
open (REDOPAGE $redopage);
while (<REDOPAGE>)
   {
   print $_;
   }
close(REDOPAGE);
}

Note that I changes 'print' to 'open'. I removed the 'exit' from the procedure. I changed 'Close' to 'close' (perl is case sensitive).

I think I found all the errors... but if it still does not work get back to me before grading the answer.

0
 

Author Comment

by:ymlew
ID: 1829730
I have tried it but it still does not work. I actually put a print statement after calling the redo sub-routine. My message got printed out, but the html just does not got showed up.

Did I miss out some library which I should have included???

Regards
Yann Ming
0
 
LVL 7

Expert Comment

by:faster
ID: 1829731
Before you print out the contents of the html, you should print the following: "Content-type: text/html\n\n".  Did you include that?
0
 
LVL 5

Expert Comment

by:icd
ID: 1829732
faster is quite right is stating that the Content-type has to be output but this would not explain why the file is not output.

The next most likely explaination is that the path to the file is wrong. The path you gave seems to be one relative to your web page root directory. This will not be the path if you (for example) telnet into the site. Assuming that your script is in the cgi-bin directory try changing the path to a relative path name, e.g.

$redopage="../olticket/jonr&d/redopage.html";

(or whatever is appropriate).

You can also put some diagnostics into your file. e.g.

open (REDOPAGE $redopage) || die "<HTML><HEAD><BODY>Cannot open file $redopage reason $!</BODY></HTML>\n";

(this should all be on one line).


0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now