A
Anonymous
Guest
Hi Guys,
still a newbie in php, I got a relative simple task to solve but I've been now spending hours and wont get this thing to work..
I can read from the txt-file, and I can write to it, but i can't get both things to work at the same time.
I want to program a little User(Admin) Interface for a Website.
The Admin should be able to edit his "news" area by himself.
What I tried is a simple textfield, which reads the "news.txt" file.
like this:
With the textarea-form it looks like this:
This works perfect so far..
now I want to edit the text in the textbox and submit it to itself (config.php), or if this might be unusefull.. to an other php-file which writes the edited text to the txt-file.
should I go on with my codings ?
ok,
here's the final..
I guess I got messed up with some variables..
My logic:
Always read the news.txt file when config.php is loaded..
when the submit button is/was pressed then (if $submit...) there have been made some changes.. save them to txt file..
what am i doing wrong ?
should the $line, when reading a file, be replaced by an array ?
is "fwrite($fp,$form1);" legal ? does the variable $form1 have the edited text as a value ?
thanks for your help..
Frank[/quote]
still a newbie in php, I got a relative simple task to solve but I've been now spending hours and wont get this thing to work..
I can read from the txt-file, and I can write to it, but i can't get both things to work at the same time.
I want to program a little User(Admin) Interface for a Website.
The Admin should be able to edit his "news" area by himself.
What I tried is a simple textfield, which reads the "news.txt" file.
like this:
Code:
$fp=fopen("news.txt","r");
while($line=fgets($fp,1024))
{
echo "$line";
}
fclose($fp);
With the textarea-form it looks like this:
Code:
<form name="form1" method="post" action="config.php">
<textarea name="textarea" cols="80" rows="10" class="baukasten">
<?php
$fp=fopen("news.txt","r");
while($line=fgets($fp,1024))
{
echo "$line";
}
fclose($fp);
</textarea>
This works perfect so far..
now I want to edit the text in the textbox and submit it to itself (config.php), or if this might be unusefull.. to an other php-file which writes the edited text to the txt-file.
should I go on with my codings ?
ok,
here's the final..
Code:
<form name="form1" method="post" action="config.php">
<textarea name="textarea" cols="80" rows="10" class="baukasten">
<?php
$fp=fopen("news.txt","r");
while($line=fgets($fp,1024))
{
echo "$line";
}
fclose($fp);
if ($submit) {
$fp=fopen("news.txt","w");
fwrite($fp,$form1);
fclose($fp);
echo ("$form1");
}
?>
</textarea>
<br>
<input type="submit" name="Submit" value="Save Changes">
</form>
I guess I got messed up with some variables..
My logic:
Always read the news.txt file when config.php is loaded..
when the submit button is/was pressed then (if $submit...) there have been made some changes.. save them to txt file..
what am i doing wrong ?
should the $line, when reading a file, be replaced by an array ?
is "fwrite($fp,$form1);" legal ? does the variable $form1 have the edited text as a value ?
thanks for your help..
Frank[/quote]