hi,
Here i re did the things for you. I just did this for you so you can learn from that. Please please go through it and try to get the idea. PLEASE DO NOT JUST COPY AND PASTE THE CODING ..
hope this is ok for you. I did some minor changes as well.
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<?php
if ($efileaction=="edit")
{
?>
<hr width="70%" align="center">
<div class="subadmintitle" align="left">Do Your Editing</div><br>
<div class="admintext" align="left">You are editing <?php echo"$fname"; ?>
<form method="POST" action="test.php">
<?php
$fileContents='';
$fp = fopen($fname, "r") or die("cannot open ".$fname);
while ($data = fread($fp, 4096))
{
$fileContents .= $data;
}
fclose($fp);
if($fileContents=='')
{
$Name='';
$Address='';
$par1='';
}
else
{
$contentArr=explode('<|<',$fileContents);
$Name=$contentArr[0];
$Address=$contentArr[1];
$par1=$contentArr[2];
}
?>
<input type="hidden" value="<?php echo $Name; ?>" name="Name">
<input type="hidden" value="<?php echo $Address; ?>" name="Address">
<input type="hidden" value="<?php echo $par1; ?>" name="par1">
<input type="hidden" value="<?php echo $_POST['fname']; ?>" name="fname">
<input type="text" value="<?php echo $Name; ?>" name="Name"><br>
<input type="text" value="<?php echo $Address; ?>" name="Address"><br>
<textarea name="par1" cols="30" rows="10" wrap="virtual"><?php echo $par1; ?></textarea>
<input type="hidden" value="efile" name="efileaction"><br>
<input type="submit" value="Save Changes">
</form>
<form method="POST" action="test.php">
<input type="hidden" value="<?php echo $Name; ?>" name="Name">
<input type="hidden" value="<?php echo $Address; ?>" name="Address">
<input type="hidden" value="<?php echo $par1; ?>" name="par1">
<input type="hidden" value="<?php echo $_POST['fname']; ?>" name="fname">
<input type="hidden" value="edit" name="efileaction"><br>
<input type="submit" value="Reload (dont save)">
</form>
</div>
<?php
}
elseif ($efileaction=="efile")
{
//edit actions
if (file_exists($_POST['fname']))
{
$fp = fopen($_POST['fname'],"w");
$par1 = stripslashes($_POST['par1']);
$par1 = htmlspecialchars($par1);
$str=$_POST['Name']."<|<".$_POST['Address']."<|<".$par1;
if(!fwrite($fp,$str))
{
print "Error writting to the file";
}
fclose($fp);
}
else
{
echo"script error";
}
?>
<hr width="70%" align="center">
<div class="subadmintitle" align="left">Complete</div><br>
<div class="admintext" align="justify">
<?php echo "Congratulations <a href=\"$fname\">$fname</a> has been edited."; ?> Go to your page to verify changes. <br><br>
<form method="POST" action="test.php">
<input type="hidden" value="form" name="efileaction">
<input type="submit" value="Edit Another File">
</form>
</div>
<?php
}
else
{
?>
<hr width="70%" align="center">
<div class="subadmintitle" align="left">Enter File Name</div><br>
<div align="justify" class="admintext">
Please enter a file that exists! You cannot leave it blank.
<br>
<form method="POST" action="test.php">
<div class="admintext">Enter File Name</div>
<input type="text" value="" name="fname"><br>
<input type="hidden" value="edit" name="efileaction"><br>
<input type="submit" value="Edit File">
</form>
</div>
<?php
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br><br>
</body>
</html>