josephman1988
Programmer
Basically, I have an index page.index.cgi, using home.tmpl
It has a section, conveniantly titled: news.
Now, i have another page, /admin/news.cgi, this has a form in which is supposed to change the news once entered.
Now the scripts:
----------
home.tmpl (THE 'DYNAMIC CHANGE'):
----------
<div id="hcn2">> News - ( <TMPL_VAR NAME="DATE"> ) -
<ul>
<li><TMPL_VAR NAME="NEWS"></li>
</ul>
</div>
----------
news.cgi (THE FORM):
----------
<form action='home.cgi' enctype='multipart/form-data' method='post'>
Date: (eg; 11/04/07 format)<br />
<input type="text" name="date" />
<br />
<br />
News:<br />
<textarea name="news" cols="50" rows="5"></textarea>
<br />
<br />
<input type="hidden" name="action" value="insert">
<input type='submit' value='submit' />
</form>
----------
And the form action (HOW THE DATA IS WRITTEN AND READ):
----------
#!/usr/bin/perl -w
use warnings;
use strict;
use diagnostics;
use CGI::Carp qw/fatalsToBrowser/;
use HTML::Template;
use CGI;
my $query = new CGI;
my $date = $query->param("date");
my $news = $query->param("news");
my $template = HTML::Template->new(filename => 'home.tmpl');
if ($query->param('action') eq 'insert') {
open (INSERT,">/home/news.txt");
print INSERT "$date|$news\n";
close(INSERT);
}
$template->param( 'date' => $date, 'news' => $news);
open (READ,"/home/news.txt");
my @data = <READ>;
close(READ);
foreach my $line (@data) {
(my $db_date, my $db_news) = split(/\|/,$line);
print "$db_date, $db_news<br>\n";
}
print "Content-Type: text/html\n\n";
print $template->output;
----------
The problem which is, that it works when i type in the data, the section which i want does change, but when i navigate to the page again, the data is there no more.
Hope this was clear, any help will be great.
It has a section, conveniantly titled: news.
Now, i have another page, /admin/news.cgi, this has a form in which is supposed to change the news once entered.
Now the scripts:
----------
home.tmpl (THE 'DYNAMIC CHANGE'):
----------
<div id="hcn2">> News - ( <TMPL_VAR NAME="DATE"> ) -
<ul>
<li><TMPL_VAR NAME="NEWS"></li>
</ul>
</div>
----------
news.cgi (THE FORM):
----------
<form action='home.cgi' enctype='multipart/form-data' method='post'>
Date: (eg; 11/04/07 format)<br />
<input type="text" name="date" />
<br />
<br />
News:<br />
<textarea name="news" cols="50" rows="5"></textarea>
<br />
<br />
<input type="hidden" name="action" value="insert">
<input type='submit' value='submit' />
</form>
----------
And the form action (HOW THE DATA IS WRITTEN AND READ):
----------
#!/usr/bin/perl -w
use warnings;
use strict;
use diagnostics;
use CGI::Carp qw/fatalsToBrowser/;
use HTML::Template;
use CGI;
my $query = new CGI;
my $date = $query->param("date");
my $news = $query->param("news");
my $template = HTML::Template->new(filename => 'home.tmpl');
if ($query->param('action') eq 'insert') {
open (INSERT,">/home/news.txt");
print INSERT "$date|$news\n";
close(INSERT);
}
$template->param( 'date' => $date, 'news' => $news);
open (READ,"/home/news.txt");
my @data = <READ>;
close(READ);
foreach my $line (@data) {
(my $db_date, my $db_news) = split(/\|/,$line);
print "$db_date, $db_news<br>\n";
}
print "Content-Type: text/html\n\n";
print $template->output;
----------
The problem which is, that it works when i type in the data, the section which i want does change, but when i navigate to the page again, the data is there no more.
Hope this was clear, any help will be great.