CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
I'm sure it's an easy problem (so please help!!)

 



wippet
Deleted

Jun 28, 2000, 5:15 PM

Post #1 of 3 (502 views)
I'm sure it's an easy problem (so please help!!) Can't Post

I hhave this little program that keeps coming up with this error "Premature end of script headers" i have looked over my code and everytthinng looks ok and i can'tt work out where the problem is coming from

I will post tthe code and tell you what i'm doing then maybe someone can help.

From the code below you can see i want to add a record to a txt file i created tthe datafile.txt and the add.html in the same file as the add.pl file, so this should not cause a problem. and in the html file i have created a form that posts the fields to the program the fields passed are name, phone, email, and notes. Can someone please help me as i'm having loads of trouble. One idea i have is that i'm not saving it right, i just copied tthe text from a txt file and saved it with a .pl extension, could this be my problem, also what is the difference between .cgi and .pl i no whhat each is but is there any difference in them

#!/usr/bin/perl
###########################
# This file adds a record #
# to the datbase. #
###########################

use CGI qw(:standard);

$EXCLUSIVE = 2;
$UNLOCK = 8;

$key=time();

$database="datafile.txt";
$returnto="add.html";
$record = join '|', $key,param(name),param(email),param(phone),param(notes);

&AddRecord($database,$returnto,$record);

sub AddRecord{
$database=$_[0];
$returnto=$_[1];
$record =$_[2];

open (DB,">>$database") or die "Error: $!\n";
#flock DB, $EXCLUSIVE; # Lock the file so nobody else uses it.
seek DB, 0, 2;
print DB "$record\n";
#flock DB, $UNLOCK;
close(DB);


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

print<<HTML;
<HTML><BODY BGCOLOR="#FFFFFF" TEXT=ARIAL>
<FONT SIZE=6><CENTER>Record Added!</CENTER></FONT><HR>
<P>
<FONT SIZE=5>Back to: <A HREF="$returnTo">$returnTo</A>
</BODY></HTML>
HTML

return;
}


Cretep
User

Jun 28, 2000, 7:14 PM

Post #2 of 3 (502 views)
Re: I'm sure it's an easy problem (so please help!!) [In reply to] Can't Post

The only thing I can see that might go wrong is the path to your text file. Try using the full path i.e. /really/long/path/text.txt. Some servers only like full paths the same goes for the .pl or .cgi extension it all depends on the server.

Good luck. Let me know how you get on.

-Peter


wippet
Deleted

Jun 29, 2000, 3:20 PM

Post #3 of 3 (502 views)
Re: I'm sure it's an easy problem (so please help!!) [In reply to] Can't Post

i have tried this relative to the server address and also relattive to the root address and still no luck. I think most of my problems are coming from using the macs and with ftping up tto my site. Someone was saying before, that the macs save the files a little different, causing problems, someone else also said i have to upload in ASCII other wise it might mess the file up. I downloaded BBedit to over come this problem I tried most formatss but nothing seems to work. Can some one fill in these questions for me????

When uploading tthe files using a mac what is the best FREE! ftp client?

What is the best FREE! text editer for the macs

Whhat is thhe besttt file formatt to save these scripts in for a unix server?


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives