Click to See Complete Forum and Search --> : SSI and CSS is CGI's


tonis
03-04-2003, 08:29 PM
I can't get a guestbook script that writes to a page to work...

is it because i am attempting to use CSS and SSI? maybe because the page i am writing to has a .shtml istead of html extension?

anyone know what to do?
print "Content-type:text/Shtml"; maybe? more than one content type?

i knwo you need the text/css when using a style sheet on a reg web page?

help i am confused as hell

tonis
03-04-2003, 08:54 PM
Method Not Allowed
The requested method POST is not allowed for the URL /nf-errors/cgi-cutoff.asis


after trying a stripped down version of the script i got that message... does this mean simply that my host doesen't allow it?

jeffmott
03-04-2003, 10:10 PM
.asis
What language is your guestbook written in?

ter trying a stripped down version of the script i got that message... does this mean simply that my host doesen't allow it?
Try running a simple "Hello World" script and see if that works for you.

tonis
03-05-2003, 09:58 PM
PERL

tonis
03-06-2003, 02:43 PM
This is the portion of the scipt


open (GUESTBOOK,"<< $guestbook");
$currenttime=localtime;


print GUESTBOOK "Content-type: text/html\n\n";
print GUESTBOOK <<EndOfHtml;
<HTML><HEAD><TITLE>WORK</TITLE></HEAD>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF>
<BR><BR><BR><BR>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=2>
<TR><TD WIDTH="190" ALIGN=LEFT VALIGN=TOP><BR><BR><BR><BR><!--#include virtual="http://clanetf.netfirms.com/www/cscnav.htm"--></TD>
<TD WIDTH="100"></TD>
<TD WIDTH="1100" ALIGN=CENTER VALIGN=TOP><img src="guestbook.jpg"> <BR></BR>
<TABLE WIDTH="145" CELLSPACING="1" CELLPADDING="4" BGCOLOR=#000033>
<TH BGCOLOR=#000055 CLASS="thead"><a href="mailto:$FORM{email}">$FORM{name}</A> -$currenttime</TH>
<TR><TD BGCOLOR=#333333>$FORM{comment}</TD></TR></TABLE><BR>
</BODY>
</HTML>

EndOfHtml
close (GUESTBOOK);

&thank_you;
}

tonis
03-06-2003, 02:58 PM
#!/usr/bin/perl
# This is the absolute pathname of the email log.
use CGI::Carp qw(fatalsToBrowser);

$guestbook="/mnt/web_a/d03/s26/a000nuxr/www/guestbookinfo.html";

# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}



# The following code posts the log entry

open (GUESTBOOK,"<< $guestbook");
$currenttime=localtime;


print GUESTBOOK "Content-type: text/html\n\n";
print GUESTBOOK <<EndOfHtml;
<HTML><HEAD><TITLE>WORK</TITLE></HEAD>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF>
<BR><BR><BR><BR>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=2>
<TR><TD WIDTH="190" ALIGN=LEFT VALIGN=TOP><BR><BR><BR><BR><!--#include virtual="http://clanetf.netfirms.com/www/cscnav.htm"--></TD>
<TD WIDTH="100"></TD>
<TD WIDTH="1100" ALIGN=CENTER VALIGN=TOP><img src="guestbook.jpg"> <BR></BR>
<TABLE WIDTH="145" CELLSPACING="1" CELLPADDING="4" BGCOLOR=#000033>
<TH BGCOLOR=#000055 CLASS="thead"><a href="mailto:$FORM{email}">$FORM{name}</A> -$currenttime</TH>
<TR><TD BGCOLOR=#333333>$FORM{comment}</TD></TR></TABLE><BR>
</BODY>
</HTML>

EndOfHtml
close (GUESTBOOK);

&thank_you;
}




#The following creates the Thank You page display

sub thank_you {

print "Content-type: text/html\n\n";
print <<EndOfHtml;
<HTML><TITLE>WORK</TITLE><HEAD></HEAD><BODY BGCOLOR=#000000><CENTER><BR><BR><BR><BR><BR><BR>
<a href="http://clanetf.netfirms.com/guestbookinfo.html">Please WORK</a></CENTER></BR>
</BODY></HTML>

EndOfHtml
exit(0);
}

jeffmott
03-06-2003, 03:19 PM
open (GUESTBOOK,"<< $guestbook");Your problem is on this line. It should be >>, not <<.

tonis
03-06-2003, 03:52 PM
still can't get it to work
should i have www in the absolute path? if my html files are located in the www folder but www is not present in the url?


#!/usr/bin/perl
# This is the absolute pathname of the email log.
use CGI::Carp qw(fatalsToBrowser);

$guestbook="/mnt/web_a/d03/s26/a000nuxr/www/guestbookinfo.html";

# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}



# The following code posts the log entry

open (GUESTBOOK,">> $guestbook");
$currenttime=localtime;


print GUESTBOOK "Content-type: text/html\n\n";
print GUESTBOOK <<EndOfHtml;
<HTML><HEAD><TITLE>WORK</TITLE></HEAD>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF>
<BR><BR><BR><BR>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=2>
<TR><TD WIDTH="190" ALIGN=LEFT VALIGN=TOP><BR></TD>
<TD WIDTH="100"></TD>
<TD WIDTH="1100" ALIGN=CENTER VALIGN=TOP><img src="guestbook.jpg"> <BR></BR>
<TABLE WIDTH="145" CELLSPACING="1" CELLPADDING="4" BGCOLOR=#000033>
<TH BGCOLOR=#000055>

EndOfHtml
print GUESTBOOK "<a href=\"mailto:$FORM{email}\">$FORM{name}</A> -$currenttime</TH>";
print GUESTBOOK "<TR><TD BGCOLOR=#333333>$FORM{comment}</TD></TR></TABLE><BR>";
print GUESTBOOK "</BODY></HTML>";
close (GUESTBOOK);

&thank_you;
}




#The following creates the Thank You page display

sub thank_you {

print "Content-type: text/html\n\n";
print <<EndOfHtml;
<HTML><TITLE>WORK</TITLE><HEAD></HEAD><BODY BGCOLOR=#000000><CENTER><BR><BR><BR><BR><BR><BR>
<a href="http://clanetf.netfirms.com/guestbookinfo.html">Please WORK</a></CENTER></BR>
</BODY></HTML>

EndOfHtml
exit(0);
}


I've changed it around many many times with no luck??? can you spot any more errors?

jeffmott
03-06-2003, 07:08 PM
should i have www in the absolute pathThat is a question for your host. But the path can also be relative. So if you make it just 'guestbookinfo.html' then it will write the file in the same directory as the script.

Nedals
03-06-2003, 07:12 PM
Are you trying to send the page to the browser or to a file?

If to the browser, remove GUESTBOOK, if to a file, remove this line...

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

Hope that helps.

Update

open (GUESTBOOK,">> $guestbook");

This line will 'append' data. I don't think that's what you want. Change it to this..

open (GUESTBOOK,">$guestbook"); # no spaces

This will clean out the old page and create a new one

jeffmott
03-07-2003, 06:35 PM
Change it to this..
open (GUESTBOOK,">$guestbook")
This will delete all previous posts to the guestbook before writing the new one.

no spaces
Spaces before or after the file name are insignificant.

This will clean out the old page and create a new one
How are they supposed to retain posts then?

Nedals
03-07-2003, 07:10 PM
jeffmott,
Your comments are right on and thank's for the clarification on the spaces.

It appeared to me that tonis is writing an entire HTML page to the guestbook which is a little strange. How do you retrieve the data? In addition, you certainly don't want to write the HTTP header to the file. That's why I was a little confused as to what is being saved and what's supposed to be sent to the browser.

So I guess my question would be, 'What is being saved to the guestbook?' and 'how is it retrieved'.

Wait a minute. This isn't my thread.
:)

tonis
03-07-2003, 09:55 PM
I am trying to make the guestbook entries appear on an HTML page(guestbookinfo.html) so that they can be read by all. I guess the concept is similar to a forum. I want an entry to be posted to a html page and each new entry to be posted below the previous one.

Thanks for your help i am going to try and place guestbook info into my cgi bin

tonis
03-07-2003, 10:10 PM
Finally got it printing to the page... you guys are all awesome thanks for bearing wiht me... i've got one last question
how would i go about only printing the information to the page?? everytime i do a test post the entire html document is recreated(i.e. the guetbook title image is placed again) is there anyway to have only the posts be printed each time someone signs it?


i'm thinking something like

open (GUESTBOOK,"> $guestbook");

print GUESTBOOK "beginning html";
close(GUESTBOOK);
open (GUESTBOOK,">> $guestbook");
print GUESTBOOK "entries(which will stay post after post";
close (GUESTBOOK);
open (GUESTBOOK,"> $guestbook");
print GUESTBOOK "ending html";
close (GUESTBOOK);

Based on the replies i've gotten from you guys i'm thinking that will do what i want but i have a feeling there is a better way to achieve the effect i want... any ideas?

Nedals
03-07-2003, 10:24 PM
The script you posted I do not believe will do the job.
Here's basically what you need to do.........
1. use strict. Its not essential but HIGHLY recomended
2. use CGI. Don't waste your time writing code for things that are already proven and working.
my $q = new CGI;
3. Decide what you want to save and create your HTML entry form with the appropiate fields.
4. When the data arrives at your script (via post), build it into a delimited string
my $guestname = $q->param('guestname');
my $guestmsg = $q->param('guestmsg');
my $listing = "$guestname|$guestmsg"; #etc
5. Append the listing to your GUESTBOOK file;
6. Maybe send an email to this guest?
That's all your listings saved.

Now to display..............
Open your file to read
my @listings = <FIL>
close FIL;
my $tableData = '';
# process each line of the file
foreach $listing @listings {
($guestname,$guestmsg) = split($listing,"|");
# put this stuff into an HTML table row. Your Choice but make sure the HTML here matchesin with the HTML below $tableData .= "<tr><td>$guestname</td><td>$guestmsg</td></tr>\n"
}

Now put the data into an HTML doc................
print "Content-type: text/html\n\n";
print <<EndOfHtml;
<HTML><HEAD><TITLE>WORK</TITLE></HEAD>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=2>
<TR><TD colspan=2><img src="guestbook.jpg"></td></tr>
$tableData
etc......
</TABLE>
</BODY>
</HTML>
EndOfHtml

exit;

I got this done before I saw you post, but here it is anyway

tonis
03-19-2003, 03:48 PM
My problem is that the image is posted again everytime someone posts.

Nedals
03-19-2003, 05:29 PM
Post a link to your site so we can see the problem. If you recoded as recomended, you will only get one picture!

tonis
03-24-2003, 11:55 AM
But what would be the url to that page?

It seems like it would be a page that is created by the cgi? How would that page be acessed by those who where not brought there by the CGI after submitting an entry?


I can't seem to get the <<marker


marker
end of file thing to work(i don't know what to call it technically.

But i think that is because i'm using it like thats

open (GUESTBOOK,">>$guestbook")
print GUESTBOOK "Content-type: text/html \n\n";
print GUESTBOOK <<END;
(all my HTML)

END

My CGI Carp error mod is saying somethinga bout not finding an instnace of it earlier... any clues

Nedals
03-24-2003, 12:52 PM
I think I get it! You want to write your guest book into an HTML file, $guestbook. Is that right?

If that's what you are doing, remove this line..

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

It's only needed when you want the script to return a page to the browser.

<<END; Here-Is identifier, and it looks fine.
This is a guess, but END might not be a good word to use (reserved maybe!), I use HTML; reminds me I'm processing an HTML doc.

tonis
03-24-2003, 03:07 PM
Yah that may be it... but i was using a bunch of different words HTML, EOF, EndOfHTML but none seemed to work i will try removing the content type line and see if it helps.


The only reason I am so interested in this is i hope to eventually script a forum... i orded a copy of CGI 201 and hopefully I will get the hang of it

tonis
03-24-2003, 03:15 PM
I don't know it just won't run


#!/usr/bin/perl
# This is the absolute pathname of the email log.
use CGI::Carp qw(fatalsToBrowser);

$guestbook="/mnt/web_a/d03/s26/a000nuxr/www/testing.html";

# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
}



# The following code posts the log entry

open (GUESTBOOK,">> $guestbook");

print GUESTBOOK "Content-type: text/html\n\n";
print GUESTBOOK <<EndOfHtml;
<HTML><HEAD><TITLE>CSC 105-- Tony Buttigieg</TITLE></HEAD>
<LINK TITLE="global css" HREF="/~www/csc.css" TYPE=text/css REL=stylesheet>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF>
<BR><BR><BR><BR>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=2>
<TR><TD WIDTH="190" ALIGN=LEFT VALIGN=TOP><BR></TD>
<TD WIDTH="100"></TD>
<TD WIDTH="1100" ALIGN=CENTER VALIGN=TOP><img src="guestbook.jpg"> <BR></BR>
$currenttime=localtime
<TABLE WIDTH=500 CELLSPACING=1 CELLPADDING=4 BGCOLOR=#000033><TH BGCOLOR=#000055>
<a href="mailto:$FORM{email}">$FORM{name}</A><I> -$currenttime</I></TH>
<TR><TD BGCOLOR=#333333>$FORM{comment}</TD></TR></TABLE><BR>
</TABLE></BODY></HTML>

EndOfHtml
close (GUESTBOOK2);

&thank_you;
}




#The following creates the Thank You page display

sub thank_you {

print "Content-type: text/html\n\n";
print <<EndOfHtml;
<HTML><TITLE>WORK</TITLE><HEAD></HEAD><BODY BGCOLOR=#000000><CENTER><BR><BR><BR><BR><BR><BR>
<a href="http://clanetf.netfirms.com/testing.html">Please WORK</a></CENTER></BR>
</BODY></HTML>

EndOfHtml
exit(0);
}

Nedals
03-24-2003, 04:48 PM
1. This path looks a little strange. Are you sure it's right?

$guestbook="/mnt/web_a/d03/s26/a000nuxr/www/testing.html";

I would expect to see something like "/home/...../www/testing.html"; When you ftp your files to the server, you should see the path
displayed in one of the fields of the ftp window.

2. Again, get rid of this. It is WRONG and does not belong here!
print GUESTBOOK "Content-type: text/html\n\n";

3. $currenttime has not been initilized so it will cause a 'error 500'.
For now add this after $guestbook="....

$guestbook=".....
$currenttime="today";

4. close (GUESTBOOK2); ..... should be.... close (GUESTBOOK);

5. &thankyou; ... should be.... &thankyou();

And you really should start using the CGI.pm module.

Nedals
03-24-2003, 05:07 PM
tonis, try this.

#!/usr/bin/perl

use CGI;
use strict;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;
my $path = "/mnt/web_a/d03/s26/a000nuxr/www"; # check to make sure this is right
my $guestbook="$path/testing.html";
my $currenttime = "today"; #need to get real time


my $name = $q->param('name');
my $email = $q->param('email');
my $comment = $q->param('comment');

# I've taken out the append mode for now. WE can put it back when all this works.
# I've also commented out the style sheet. That doesn't look right either!
open (GUESTBOOK,">$guestbook") || die "Cannot open $guestbook";

print GUESTBOOK <<EndOfHtml;
<HTML><HEAD><TITLE>CSC 105-- Tony Buttigieg</TITLE></HEAD>
<!--LINK TITLE="global css" HREF="/~www/csc.css" TYPE=text/css REL=stylesheet-->
<BODY BGCOLOR="#000000" TEXT="#FFFFFF">
<BR><BR><BR><BR>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=2>
<TR><TD WIDTH="190" ALIGN=LEFT VALIGN=TOP>&nbsp;</TD>
<TD WIDTH="100"></TD>
<TD WIDTH="1100" ALIGN=CENTER VALIGN=TOP><img src="guestbook.jpg"><BR></BR>$currenttime=thetime
<TABLE WIDTH=500 CELLSPACING=1 CELLPADDING=4 BGCOLOR="#000033">
<TH BGCOLOR="#000055"><a href="mailto:$email">$name</A><I> -$currenttime</I></TH>
<TR><TD BGCOLOR="#333333">$comment</TD></TR>
</TABLE>
</td></tr>
</TABLE>
</BODY>
</HTML>
EndOfHtml
close (GUESTBOOK);

&thank_you();
exit;

#========= SUBROUTINES
sub thank_you {
print "Content-type: text/html\n\n";
print <<EndOfHtml;
<HTML><TITLE>WORK</TITLE><HEAD></HEAD>
<BODY BGCOLOR=#000000>
<CENTER><BR><BR><BR><BR><BR><BR>
<a href="http://clanetf.netfirms.com/testing.html">Please WORK</a></CENTER></BR>
</BODY>
</HTML>
EndOfHtml
}

UPDATE:
I've reposted the above code which now operates correctly with my Perl interpeter. Cut and paste into a .cgi file and it should work for you. Once this is working we can start to add the other things you need.