Help me with my form please.

D

David Baker

I am a total newbie, and have no idea what I am doing. I have created
a html form, and am tring to pass some variable to a perl script to
make it update a guest book. When ever I press submit on my form, I
get a "HTTP 500 - Internal server error". I checked and the server is
working fine. Here is my code. If anyone has any idea's I really
appreciated it.


#!/user/bin/perl

if($ENV{'REQUEST_METHOD'} eq 'GET')
{
$in_string= $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $in_string, $ENV{'CONTENT_LENGTH'});
}

@an_array = split('&', $in_string);

$array_length = @an_array;

for($i=0; $i<$array_length; $i++)
{
($var_name, $value) = split('=', $an_array[$i]);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-f0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$var_name =~ tr/+/ /;
$var_name =~ s/%([a-fA-F0-9][a-fA-F0-9]/pack("C", hex($1))/eg;
$var_name =~ s/<!--(.|\n)*-->//g;

$in_vars{$var_name} = $value;
}



open (LOG, ">>../LOG.txt");
print LOG ("Name: $in_vars{'username'}\nEmail Address:
$in_vars{'email'}\nWeb site: $in_vars{'website'}\nHow you found this

site: $in_vars{'R1'}\nYou said: {'Comment'}\n\n----\n\n");
close (LOG);
 
P

Paul Lalli

I am a total newbie, and have no idea what I am doing. I have created
a html form, and am tring to pass some variable to a perl script to
make it update a guest book. When ever I press submit on my form, I
get a "HTTP 500 - Internal server error". I checked and the server is
working fine. Here is my code. If anyone has any idea's I really
appreciated it.


#!/user/bin/perl
^^^^

This is probably not what you want. Unless your system is very different
from most, you want
#!/usr/bin/perl

Add these three lines to your script, right after the first line
use strict;
use warnings;
use CGI qw:)standard);

The entirety of this next section of this program is ancient and should
not be used. Delete the bookmark to whatever site gave you this code.
if($ENV{'REQUEST_METHOD'} eq 'GET')
{
$in_string= $ENV{'QUERY_STRING'};
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN, $in_string, $ENV{'CONTENT_LENGTH'});
}

@an_array = split('&', $in_string);

$array_length = @an_array;

for($i=0; $i<$array_length; $i++)
{
($var_name, $value) = split('=', $an_array[$i]);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-f0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$var_name =~ tr/+/ /;
$var_name =~ s/%([a-fA-F0-9][a-fA-F0-9]/pack("C", hex($1))/eg;
$var_name =~ s/<!--(.|\n)*-->//g;

$in_vars{$var_name} = $value;
}

All of that should go away.

Read up on CGI.pm by typing
perldoc CGI
on the command line, or by going to
http://www.perldoc.com/perl5.6/lib/CGI.html

That will tell you about the param() function, and how to get your form
elements.

Paul Lalli
 
G

gnari

in addition to what Paul said, let me add:
open (LOG, ">>../LOG.txt");

you do not check if the open() fails
you assume that ../ has a meaning

do you realize that you might want to lock the file ?

gnari
 
D

dan baker

I am a total newbie, and have no idea what I am doing. I have created
a html form, and am tring to pass some variable to a perl script to
make it update a guest book. When ever I press submit on my form, I
get a "HTTP 500 - Internal server error".
----------
besides the code errors, http 500 errors often indicate that the
script has the wrong privs. you need to chmod the script to rwxr-xr-x
so the server can execute it. it also needs to be in a dir that the
server allows to BE executed, usually cgi-bin.

d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top