Jump to content

Perl For Cgi. -help!


Evilseperoth
 Share

Recommended Posts

Well im new to scripting and i attepmted to right a basic guest book that i am going to one day turn into a full blown forum. I was just wondering if any one can point out what i did wrong on this script. Please HELP!

 

#!/usr/bin/perl

use CGI;

 

my $cgi = CGI->new();

 

 

my $name = $cgi->param('name');

my $msg = $cgi->param('msg');

 

 

if (length ($name) > 50 || length ($msg) > 2000) {

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

print "Your name or message was too long.";

exit;

}

 

 

$msg =~ s/[\n\r]/<br>/g;

 

 

open (LOG, ">>msg_log.txt") || die ("Can't open msg_log.txt: $!");

flock (LOG);

print LOG "$name wrote: $msg\n";

close (LOG);

 

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

print "Thanks for your message";

exit;

 

I suck at de-buggin and cant seem to figure it out. so please help. :D

Link to comment
Share on other sites

I de-bugged your script. It was about 99% there and just had a few syntax errors.

 

I'll give you a choice, you can give it a shot on your own, or I can give you the answer. If you're intending on building anything significant I suggest giving it a try with some guidance. I usually learn better from doing things myself.

 

Here's a hint for you. Insert the following bolded line into the top of your code so you can see more descriptive errors:

 

**********************

#!/usr/bin/perl

use CGI;

 

my $cgi = CGI->new();

use CGI::Carp qw(fatalsToBrowser);

 

my $name = $cgi->param('name');

my $msg = $cgi->param('msg');

**********************

 

 

Give that a try and see if you can figure the rest out. If you get suck again, you can always ask for another hint.

 

Good luck!

 

Bill

Link to comment
Share on other sites

i bewlive i found the problum but it is a super major one. for some reason i cannot get a param to print out no matter how i try it. ive tryed:

 

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

 

print param('name');

and

$name = param('name');

print $name;

and

$CGI = cgi->new;

$name=$cgi->param('name');

print $name;

 

im not sure why. and i know about permissions.

Link to comment
Share on other sites

Hi!

 

Sorry for my late response. I had THOUGHT I subscribed to this topic ... I guess I hadn't.

 

This is a code snip from one of my progams in production:

 

*****************************

#!/usr/bin/perl

 

use CGI;

use CGI::Carp qw(fatalsToBrowser);

$query = new CGI;

$pnum=$query->param('pnum');

******************************

 

I assure you that this does work. If you are finding that you still arn't getting anything from your form to print out in your script you can check:

 

1) The "name" value in your form. Make sure that it is exactly what you have specified.

2) The "action" for your form. Make sure that the script form action is exactly the same as the name of your script.

3) Double check permissions, just in case. If you are able to print anything, you're probably Ok.

4) How did you get your script where it is? If your script was put up using FTP it MUST be in ASCII format. Binary format will not work. If you're not sure, delete your script and re-upload it in the correct format. FrontPage can mess this up for you too. Don't use it for scripts.

 

If none of this works, you might want to send me the files (your HTML form and perl script file) and I'll figure it out.

 

We'll get through this!

 

PS - Good on-line reference for you: http://iis1.cps.unizar.es/Oreilly/perl/

 

If there's anything you need to learn, it's probably in that link.

 

Good luck!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...