Text editor code help
Posted: Wed Jun 11, 2008 12:53 pm
I'm new to PHP and to this forum so any help with that in mind is appreciated.
Problem: I am writing a simple text editor using the fopen, fwrite, fclose and get_contents commands.
I have succeeded in getting the window to come up and drop in the existing text to edit but it is not saving. I am wondering if it has something to do with the mode I am using for fopen. I tried a couple other modes like 'a', 'a+' and 'r+' but am not having any luck. Here is my code:
//this is the get contents file
<?php
$filename = "../basictext.php";
$contents = file_get_contents($filename);?>
<form method="post" action="process.php">
<textarea cols="75" rows="30" name="content">
<?php echo $contents;?>
</textarea><br>
<input type="submit" name="Save" value="SAVE"></p>
</body>
//this is the processor
<?php
$contents = $_POST['contents'];
$filename = "../basictext.php";
$fp = fopen($filename, 'w');
fwrite($fp, $contents);
fclose($fp);
?>
Problem: I am writing a simple text editor using the fopen, fwrite, fclose and get_contents commands.
I have succeeded in getting the window to come up and drop in the existing text to edit but it is not saving. I am wondering if it has something to do with the mode I am using for fopen. I tried a couple other modes like 'a', 'a+' and 'r+' but am not having any luck. Here is my code:
//this is the get contents file
<?php
$filename = "../basictext.php";
$contents = file_get_contents($filename);?>
<form method="post" action="process.php">
<textarea cols="75" rows="30" name="content">
<?php echo $contents;?>
</textarea><br>
<input type="submit" name="Save" value="SAVE"></p>
</body>
//this is the processor
<?php
$contents = $_POST['contents'];
$filename = "../basictext.php";
$fp = fopen($filename, 'w');
fwrite($fp, $contents);
fclose($fp);
?>