Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing content via a restricted page

Status
Not open for further replies.

josephman1988

Programmer
Sep 30, 2007
4
GB
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.
 
Have you checked the /home/news file and see if the data is really there and it is a display problem or if the data disappears from there to?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
After checking the news.txt file, there seems to be nothing there. Could this be because im writing (>) and not appending(>>)?
 
I changed:

open (INSERT,">/home/news.txt");

to
open (INSERT,">news.txt");

This allows the data to be written to news.txt, but i just get a misconfiguration error, aswell as a 404 error for /home/home.cgi which only occurs after this change. ?
 
Code:
open (INSERT,">/home/news.txt");

This line looks odd to me. It appears like your server is running on Linux, and a standard in Linux is that a file directly in /home wouldn't be editable (unless you specially configured your system to allow it)

It would usually be more along the lines of, /home/username/news.txt

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
/home/ is a directory i created to allow a intro page to be added.

therefore, news.txt would be in the home directory, that would be editable, correct?
 
this is better written like so:

foreach my $line (@data) {
my ($db_date, $db_news) = split(/\|/,$line);
print "$db_date, $db_news<br>\n";
}

but you are trying to print the above data before printing an http header. The script should throw you an error.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
shouldn't /home/ have already existed?

Your not thinking that /home is part of your web are you ??
like ?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
When you tell us about your /admin/ and /home/, where are these directories relative to? Your domain name or the file system that the server is running on?

Like, if your DocumentRoot is, say, /home/soandso/public_html, then " would be using the file /home/soandso/public_html/admin/news.cgi on the internal file system.

So, when you want to edit "/home/news.txt", are you trying to edit the file that would be at " Because if that's the case, you're going about it all wrong.

Your Perl scripts are executed on the server machine as a program. Therefore, "/" means "the root of the file system", and NOT the DocumentRoot on your website. So, "/home/news.txt" literally means "/home/news.txt", and not i.e. "/home/soandso/public_html/home/news.txt"

So that's why I said, the fact that you're editing /home/news.txt stood out to me, because that typically shouldn't be done. If this is a Linux-based server, all that's in /home are directories for different users.

The fact that you said you created the /home directory is even more unusual. Either you'd be on a special distro of Linux in which user home directories are not kept in /home by default, or you're on Windows where /home is actually C:/home.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top