Hello,
I have 1 file notex.php with both form and php scripting .
FORM IS THIS :
----------------------

<form action="notesx.php" method="post">		
<fieldset>
<legend>
Capítulo 01:
</legend>
<textarea  id='userInput' name="textspace" value="'.$textspace.'" cols="40" rows="3" ></textarea> 
<br>
<input type="submit" name="save" value='save'/>
<input type="submit" name="edit" value='edit'/>
<input type="submit" name="show" value='show'/>

<br>
<p><b id='boldStuff2'></b> </p> 

</fieldset>
</form>

and
PHP code is this :
---------------------------------

<?php


if ($_POST['save'])
{
$space = $_POST['textspace'];
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $space);

fclose($fh);
echo "Saved";
} 

if ($_POST['edit'])
{

$textspace="rajan";



} 

if ($_POST['show'])
{
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
if(filesize($myFile)!=0)
{
$theData = fread($fh, filesize($myFile));
}
else
{
echo "The file is empty";
}
fclose($fh);
echo $theData;

} 


?>

Now,this is what I want.Well,write and read is working great,but i want that when edit button is pressed the TEXTAREA is updated/filled with the file's content/data .for testing purposes I just assigned rajan to $textspace,hence if it works correct,on pressing edit button the TEXTAREA must be updated with rajan.Please help !!! I am not sure of using this syntax value="'.$textspace. in the TEXTAREA .. pLEASE GUIDE ME !! tHANKS IN ADVANCE ..

Then you need another form in the block of "edit".

echo "<textarea id='userInput' name=\"textspace\" cols=\"40\" rows=\"3\" >".$textspace."</textarea>";

So, when the user edits the form and clicks on submit, write the contents back to the file (or whatever!).


Edit: Btw, its (language = php, java, c, etc) and not [code language=] :)[code=language] (language = php, java, c, etc) and not :)[code language=] :)

You should be placing the variable in between the textarea tags with a conditional:

<textarea id='userInput' name="textspace" value="" cols="40" rows="3" >
<?php
if(isset($_POST)){
echo $textspace;
}
?>
</textarea>

and for the edit, you've just got to read the file and assign it to a variable:

if ($_POST['edit']){
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
	if(filesize($myFile)!=0)
	{
	$textspace = fread($fh, filesize($myFile));
	}
	else
	{
	$textspace= "The file is empty";
	}
	fclose($fh);
}

buddylee : thanks,but nothing happened .
nav33n : using your code,after pressing edit it is creating a new TEXTAREA under old TEXTAREA and hence has no relationship with the save button.on using save button,it saved empty old TEXTAREA .hence nothing happened .. Please suggest me something with which the content appears on old TEXTAREA and does not creates a new text area .Thanks a lots ..
if you want to see whole sorurce code here it is :
http://paste.dprogramming.com/dpw21l4f
Thanks again,pLEASE HELP !!

This is the file that I have working:

<?php
if ($_POST['save'])
{
$space = $_POST['textspace'];
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $space);

fclose($fh);
echo "Saved";
}
if ($_POST['edit']){
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
	if(filesize($myFile)!=0)
	{
	$textspace = fread($fh, filesize($myFile));
	}
	else
	{
	$textspace = "The file is empty";
	}
	fclose($fh);
}
if ($_POST['show'])
{
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
if(filesize($myFile)!=0)
{
$theData = fread($fh, filesize($myFile));
}
else
{
echo "The file is empty";
}
fclose($fh);
echo $theData;
}
?> 
<form action="notesx.php" method="post">
<fieldset>
<legend>
Capítulo 01:
</legend>
<textarea id='userInput' name="textspace" value="" cols="40" rows="3" >
<?php
if(isset($_POST['edit'])){
echo $textspace;
}
?>
</textarea>
<br>
<input type="submit" name="save" value='save'/>
<input type="submit" name="edit" value='edit'/>
<input type="submit" name="show" value='show'/>

<br>
<p><b id='boldStuff2'></b> </p>

</fieldset>
</form>

Try this.

<?php
if ($_POST['save']) {
	$space = $_POST['textspace'];
	$myFile = "testFile.txt";
	$fh = fopen($myFile, 'w') or die("can't open file");
	fwrite($fh, $space);
	fclose($fh);
	echo "Saved";
} 
if ($_POST['edit']) {
	$myFile = "testFile.txt";
	$fh = fopen($myFile, 'r');
	if(filesize($myFile)!=0) {
		$textspace= fread($fh, filesize($myFile));
	} else {
		$textspace= "The file is empty";
	}
	fclose($fh);
} 
if ($_POST['show']) {
	$myFile = "testFile.txt";
	$fh = fopen($myFile, 'r');
	if(filesize($myFile)!=0) {
		$theData = fread($fh, filesize($myFile));
	} else {
		echo "The file is empty";
	}
	fclose($fh);
	echo $theData;
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
    <title>atlas Am&eacute;rica (mockup) - Temario</title>   
   <link rel="stylesheet" type="text/css" href="../../lib/css/contacto.css" />
    <link rel="alternate stylesheet" type="text/css" href="css/print.css" title="Print" />
    <link rel="icon" href="../../imgs/notes.ico" />
    <link rel="shortcut icon" href="../../imgs/notes.ico" type="image/x-icon" />
</head>

<body>
<div id="everything">
    <div id="header">    
        <a href="../base.htm"><img src="../../imgs/banner-small.png" alt="atlas America v0.1 (mockup)" /></a>
        <h1><a href="base.htm">atlas America v0.1 (mockup) </a></h1>            
        <ul>
            <li id="last"><a href="../../html/base.htm"><font size="2"></>Indice de temas</font></a></li>
            <li id="last"><a id="first" href="../index.htm">Salir</a></li>
        </ul>

    </div>
    <div id="sidenav-content">

    <br clear="all" />

    <div id="imgizq">
        <img src="../../imgs/juanIndice2.png" />
    </div>
    
    <div id="indice">
        <h1>Notas</h1>
<form action="notesx.php" method="post">        
<fieldset>
<legend>
Capítulo 01:
</legend>
<textarea  id='userInput' name="textspace" cols="40" rows="3" >
<?php if(!empty($textspace)) { echo $textspace; } ?>
</textarea> 
<br>
<input type="submit" name="save" value='save'/>
<input type="submit" name="edit" value='edit'/>
<input type="submit" name="show" value='show'/>

<br>
<p><b id='boldStuff2'></b> </p> 

</fieldset>
</form>

    </div>

</div>


<br clear="all" />



<div id="footer">atlas Am&eacute;rica Mockup - Software Libre M&eacute;xico</div>


</div>
<p>
    <a href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-xhtml10"
        alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
</p>
</body>
</html>

I have modified your code just a lil to make it look organised.

Cheers,
Nav


Edit: Oops! I didn't see buddylee17's post. My internet is being weird !

buddylee17 : Thanks ! its working now (may b i missed something earlier ) you rock !!
nav33n : Thanks a lots for your great help,really appreciate that .
This Daniweb is awesome.Thanks !

This article has been dead for over six months. Start a new discussion instead.