[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] saving files



Hello everyone:

I  have just  been able to make the script work.  It is working fine
except 
for one little snag.  

when I call the page from the browser , fill in the form and submit, the
browser shows all the fields including the name.  But when I submit the
form for the second time, the brower fails to show the earlier recorded
name.  All other data reamins.  Only the current one is maintained.   
Is there any way that I can save all the names? 

When I checked the database file, I found that it recorded every field
but it does not show.

Can someone run the samll programme and check.  Please fill in twice
and see the difference. 

Thanks 

Amitava



#!/usr/bin/perl  -w

use 5.004;
use strict;
use CGI qw (:standard);

### ==========
sub bail {
### ==========
  my $error = "@_";
  print h1 ("Unexpected Error"), p ($error), end_html; die $error; }

my ($CHATNAME, $MAXSAVE, $TITLE, $cur, @entries, $entry);

$TITLE= "Incas' Guestbook";
$CHATNAME = "chatfile.txt";
$MAXSAVE = 10;

print header, start_html ($TITLE), h1 ($TITLE);
$cur=CGI->new();
if ($cur->param("message")) {
$cur->param("date", scalar localtime);
@entries=($cur);
}
open (CHANDLE,"+< $CHATNAME") || bail ("cannot open $CHATNAME: $!");
	while (!eof (CHANDLE) && $#entries<$MAXSAVE) {
  		$entry=CGI->new(\*CHANDLE);
  		push @entries, $entry; 
}
seek(CHANDLE,0,0) || bail ("cannot rewind $CHATNAME: $!");
	foreach $entry (@entries) {
  		$entry->save(\*CHANDLE); 
}
truncate (CHANDLE, tell (CHANDLE)) || bail ("cannot truncate
$CHATNAME:$!");
	close (CHANDLE) || bail ("cannot close $CHATNAME: $!");

print hr start_form;
print p ("Name:",$cur->textfield(
        -NAME =>"name",
        -OVERRIDE=>1,
        -SIZE=>30));
print p ("Message:",$cur->textfield(
        -NAME=>"message",
         -OVERRIDE=>1,
        -SIZE=>40));
print p ("E-Mail:",$cur->textfield(
        -NAME=>"email",
        -OVERRIDE=>1,
        -SIZE=>30));
print p (submit ("send"), reset ("clear"));

print end_form, hr;
print h2 ("View Guest Book Entries");
foreach $entry (@entries) {
  printf  "%s  [%s]:%s %s ",
        $entry -> param ("date"),
        $entry -> param ("name"),
        $entry -> param ("message"),
        $entry -> param ("email");
                  print br (); }
print end_html;


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org