Html forms not working-cgi prob?

ReeRee

New Member
Messages
6
Reaction score
0
Points
0
HI all! I am having issues with my webpage and am too frustrated to think of an answer :rant2:. I read all the posts on similar probs I could find, most were resolved and said start new thread, so I am doing just that.

First, a brief synopsis of what I am going for with the page: I have some html forms and a perl cgi script. The script should take the input of the forms, and 'print' it to a txt file. That file then is displayed at the bottom of said page using CSS.

I have the forms in place, a script that SHOULD work, and the txt file displayed. The problem is: the cgi is doing nothing. I can't seem to figure this out :dunno:. I checked and rechecked the code (an area I am not too comfortable with in the first place) and it seems fine. I tried looking into the Perl mods on CPX, but that only confused me more. I even tried to go a different route with php/mysql, and after 5 hours of pulling hair I said :thefinger that.

Am I missing other components? Does my script need work? Is it my html? I have no clue. PLM is the page.

My Perl script is the cgi-bin subfolder of public_html and reads:
Code:
[I]#!/usr/bin/perl[/I]
 
[B]use[/B] strict;
[B]use[/B] warning;
[B]use[/B] diagnostics;
 
[B]use[/B] CGI;
[B]my[/B] $cgi = CGI->new;
[B]my[/B] $name = $cgi->param[U]([/U]'name'[U])[/U];
[B]my[/B] $class = $cgi->param[U]([/U]'class'[U])[/U];
[B]my[/B] $level = $cgi->param[U]([/U]'level'[U])[/U];
 
[B]open[/B][U]([/U]outputfile,"/kos.txt"[U])[/U]; 
[B]print[/B] [U]([/U]outputfile "$name \n<br>  $class \n<br> $level \n<br>"[U])[/U];
[B]close[/B][U]([/U]outputfile[U])[/U];
 
[B]print[/B] "Location: plmkos.html\n\n";
[B]exit[/B];

What other info (if any) do I need to post? Am I even in the right forum?
Any and all help is most welkum.
Thanks! :biggrin:
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
* Moved to Programming Help, this is where you should post for any programming related issues. If you think that there is a problem with your account then you can post back in the free hosting support section, but that is generally reserved for account issues because normal users can't post to help you there.

Good luck! :biggrin:
 

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
Change this :

Code:
open(outputfile,"kos.txt");

to

Code:
open(outputfile,">kos.txt");

That should solve your problem..



Also I've noticed that you are using / there which points to root directory..
I hope you have permission to that directory.

HTH
 
Last edited:

ReeRee

New Member
Messages
6
Reaction score
0
Points
0
Unfortunately that change had no effect. The page does nothing still. As for permissions, how do I check that?

Thanks for your help.

Edit: Thanks for the move Verb :D
 
Last edited:

bugfinder

Retired
Messages
2,260
Reaction score
0
Points
0
If you go into the file manager and select the file theres a permissions icon at the top.
 

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
What i'm referring to on the permission is that you are using / on your code. This / thing points you to the root directory.

Code:
open(outputfile,"/kos.txt");
Are you sure that your account has permission access that / directory? If you dont have access then please use other directory (you may use /home/youraccountname/) in which you are allowed to or simply remove that '/' character.

And also as bugfinder said, maybe the script you made doesnt have permission to execute, please follow what he said, change its permission to 755.

HTH.
 
Last edited:

ReeRee

New Member
Messages
6
Reaction score
0
Points
0
Ok, now I know to what you were referring, all is as it should be. The root dir is the public_html folder, so yeah permission granted. As for the other permissions, all were/are set to 755.

Is there something else I need to include in the script folder other than the script itself?

Thanks again for your support.
 
Last edited:

marshian

New Member
Messages
526
Reaction score
9
Points
0
I know nothing of perl at all, but are you sure the root dir is public_html?
as far as i know, public_html is /home/yourname/public_html
 

ReeRee

New Member
Messages
6
Reaction score
0
Points
0
Tried changing all the directories, to no avail. really frustrated atm. Maybe I should give php/mysql another shot? any other suggestions?
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
First, your html is a little messed up. You have the submit image after the closing <form> tag, so that won't submit. Also, you specify the form's action as:

http://plm.pcriot.com/home/reeree/public_html/cgi-bin/submit_kos.pl

You need to change that to '/cgi-bin/submit_kos.pl'. Lastly, you use the names 'Class' and 'Level' in the html, but you use 'class' and 'level' in the script.

And as for the script, you're missing the 's' in "use warnings;" for one. Second, you need to change

open(outputfile,"/kos.txt");

to

open(outputfile,">../kos.txt");

to specify that you want to rewrite the file and to navigate out of the cgi-bin directory. And you should also change the redirection to:

print "Location: http://plm.pcriot.com/plmkos.html\n\n";

Those changes *should* fix it.
 

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
Yeah, woiwky is right!
I was not able to see your html page earlier

Change this:

Code:
<form method="post" action="http://plm.pcriot.com/home/reeree/public_html/cgi-bin/submit_kos.pl">

to
Code:
<form method="post" action="http://plm.pcriot.com/cgi-bin/submit_kos.pl">

Please follow all of woiwsky's suggestion.

HTH
 
Last edited:

ReeRee

New Member
Messages
6
Reaction score
0
Points
0
Most of those changes were in my original files. The form end is what nailed me. Thanks for the help! Got a 500 Internal server error now, but at least it's DOING something ...will continue to work on it.

New Script:
Code:
#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use CGI;

my $cgi = CGI->new;
my $name = $cgi->param('Name');
my $class = $cgi->param('Class');
my $level = $cgi->param('Level');

open(outputfile,">http://plm.pcriot.com/kos.txt"); 
print (outputfile "$name \n<br>  $class \n<br> $level \n<br>");
close(outputfile);

print "Location: http://plm.pcriot.com/plmkos.html\n\n";

exit;

Edit: Searched other posts, and made sure permissions were set correctly (Folders/cgi files: 755, other files: 644).

PS Edit: No longer getting a 500 Error, however, the srcipt is not adding new input to the kos.txt file. About to give up, and scrap this project. It's making me so GRRRRRRRR!
 
Last edited:

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
If you want to add a new entries on that file.. Just add another > on it..

Code:
open(outputfile,">>kos.txt");
 

ReeRee

New Member
Messages
6
Reaction score
0
Points
0
>> Did not work :( I don't know what to do with it. When you hit submit, it looks like it's going to do something, but doesn't. I give up.
 
Last edited:

Jose Magsino

New Member
Messages
53
Reaction score
0
Points
0
Ok, theres nothing i can do with that if you give up.
btw, the one you wrote..

open(outputfile,">>http://plm.pcriot.com/kos.txt");

Really, really wont work..

I thought you are using what has been suggested to use :
open(outputfile,">>../kos.txt");

Ok, thanks and more power to you.
 

martin_f

New Member
Messages
4
Reaction score
0
Points
0
Why "thread is closed"??? Html forms really not working by Perl access!

In accordance with CGI specification:

  1. server must fill environment variable QUERY_STRING by form data and pass same data into @ARGV when used GET method;
  2. server must set environment variable CONTENT_LENGTH in actual data length and the data can be accessed by read from <STDIN>.
I try both methods (using CGI.pm or directly, without it) and check environment variables simultaneously. And QUERY_STRING always is empty and CONTENT_LENGTH always equal 0.

At the same time php-code:
Code:
<?php
if (isset($_POST['submit'])) {
echo "Form submitted. Data: <br>";
$i = 1;
foreach ($_POST as $name => $value) {
echo "Input $i<br> <b>Name:</b> $name<br> <b>Value:</b> $value <br><br>";
$i++;
}
echo "<br><br><br>";
}
?>
work correctly.

Your comments?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Most of those changes were in my original files. The form end is what nailed me. Thanks for the help! Got a 500 Internal server error now, but at least it's DOING something ...will continue to work on it.
To best deal with script errors, run the script on a development server of your own. Alternatively, use CGI::Carp to send errors to the browser. Only use CGI::Carp during development. As you might accidentally leave it enabled in a script, the better approach is using a development server separate from the production server.

Code:
open(outputfile,">http://plm.pcriot.com/kos.txt");
Bare file handles are all uppercase (eg OUTPUTFILE), which doesn't matter since you should store the file handle in a scalar. Also, you can't write to a URL. You should test that the open was successful. For instance, permissions will easily prevent the file from being opened.

Code:
$outPath = $ENV{'DOCUMENT_ROOT'} . '/data/kos.txt';
if (open($outfile, '>>', $path)) {
  print $outfile "$name <br>\n  $class <br>\n $level <br>\n";
  close($outfile);
  print $cgi->header(-location => 'http://plm.pcriot.com/plmkos.html');
} else {
  our $err="$!";
  print $cgi->header(-type => 'text/plain');
  print "Couldn't open data file for appending: $err\n";
}

Code:
exit;
"exit" is redundant, as this is the end of the script.

If you don't already have it, get the Camel book.


Now, on to martin_f's post.
In accordance with CGI specification:

  1. server must fill environment variable QUERY_STRING by form data and pass same data into @ARGV when used GET method;
Command line arguments are use only for ISINDEX queries, not form submissions, according to the spec.

  • server must set environment variable CONTENT_LENGTH in actual data length and the data can be accessed by read from <STDIN>.
STDIN is consumed by CGI.pm, if you use it.

I try both methods (using CGI.pm or directly, without it) and check environment variables simultaneously. And QUERY_STRING always is empty and CONTENT_LENGTH always equal 0.

Hmm... QUERY_STRING and CONTENT_LENGTH are set for me in the following when placed on Absolut. First, the form (cgitst.html):
HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>CGI ENV test</title>
  </head>

  <body>
    <h1>CGI ENV test</h1>

    <form action="/cgi-bin/cgitst?foo=bar" method="POST" name="CGI_pm">
	  <input name="bam" value="bug-AWWK!" /><input type="submit" value="Submit (use CGI)"/>
	</form>
    
    <form action="/cgi-bin/cgi-ncgi?foo=bar" method="POST" name="NoCGI_pm">
	  <input name="bam" value="bug-AWWK!" /><input type="submit" value="Submit (no CGI)" />
	</form>

  </body>
</html>
Next, cgitst, which uses CGI.pm:
Code:
#!/usr/bin/perl

use CGI qw/:standard/;

print header(-type => 'text/plain');

foreach my $key (qw(CONTENT_LENGTH QUERY_STRING)) {
    print "$key: $ENV{$key}\n";
}

print "STDIN: <<EOF\n";
while (<STDIN>) {
  print '  ', $_;
}
print "\nEOF\n";

print "Parameters:\n";
foreach $name (sort(param())) {
    print "  $name=\"", param($name), "\"\n";
}

print '@ARGV: (', join(', ', @ARGV), ")\n";

Finally, cgi-ncgi, which doesn't use CGI.pm:
Code:
#!/usr/bin/perl

print "Content-type: text/plain\n\n";

print "Not using CGI module.\n";

foreach my $key (qw(CONTENT_LENGTH QUERY_STRING)) {
    print "$key: $ENV{$key}\n";
}

print "STDIN: <<EOF\n";
while (<STDIN>) {
  print '  ', $_;
}
print "\nEOF\n";

print '@ARGV: (', join(', ', @ARGV), ")\n";
 
Last edited:
Top