edit page with a form and php
Posted: Sat Oct 18, 2008 3:03 pm
<form method="post" action="index.php?saving=1">
<textarea name="content" style="width:100%"><?php include "content.php"?>
</textarea>
<input type="submit" value="Save">
</form>
<?php
$saving = stripslashes($_REQUEST['saving']);
$content = stripslashes($_POST['content']);
$file = "content.php";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
if ($saving == 1){
fwrite($fp, $content) or die("Couldn't write values to file!");
fclose($fp);
echo "Saved to $file successfully!";
}
?>
I am stuck at this code.
It should be a page where you can edit a certain text file. The text should be included in the form as initial value, and saved/modified when hit save button.
Can someone help, i have no clue anymore and I'm pulling my hair !
I guess it must be conditioned with save==1 or ==0 , to not erase everything, just include the file (content.php in this case) to be modified then included again !??!
Thanks a lot for any answers !
<textarea name="content" style="width:100%"><?php include "content.php"?>
</textarea>
<input type="submit" value="Save">
</form>
<?php
$saving = stripslashes($_REQUEST['saving']);
$content = stripslashes($_POST['content']);
$file = "content.php";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
if ($saving == 1){
fwrite($fp, $content) or die("Couldn't write values to file!");
fclose($fp);
echo "Saved to $file successfully!";
}
?>
I am stuck at this code.
It should be a page where you can edit a certain text file. The text should be included in the form as initial value, and saved/modified when hit save button.
Can someone help, i have no clue anymore and I'm pulling my hair !
I guess it must be conditioned with save==1 or ==0 , to not erase everything, just include the file (content.php in this case) to be modified then included again !??!
Thanks a lot for any answers !