•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,594 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,652 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 737 | Replies: 6
![]() |
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hello,
I have 1 file notex.php with both form and php scripting .
FORM IS THIS :
----------------------
[code language=html]
<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>
[/code]
and
PHP code is this :
---------------------------------
[code language=php]
<?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;
}
?>
[/code]
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 ..
I have 1 file notex.php with both form and php scripting .
FORM IS THIS :
----------------------
[code language=html]
<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>
[/code]
and
PHP code is this :
---------------------------------
[code language=php]
<?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;
}
?>
[/code]
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 ..
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Then you need another form in the block of "edit".
So, when the user edits the form and clicks on submit, write the contents back to the file (or whatever!).
Edit: Btw, its [code=language] (language = php, java, c, etc) and not [code language=]
php Syntax (Toggle Plain Text)
echo "<textarea id='userInput' name=\"textspace\" cols=\"40\" rows=\"3\" >".$textspace."</textarea>";
Edit: Btw, its [code=language] (language = php, java, c, etc) and not [code language=]
Last edited by nav33n : Jul 11th, 2008 at 5:10 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
You should be placing the variable in between the textarea tags with a conditional:
and for the edit, you've just got to read the file and assign it to a variable:
php Syntax (Toggle Plain Text)
<textarea id='userInput' name="textspace" value="" cols="40" rows="3" > <?php if(isset($_POST)){ echo $textspace; } ?> </textarea>
php Syntax (Toggle Plain Text)
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); }
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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 !!
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 Syntax (Toggle Plain Text)
<?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>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Try this.
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 !
php Syntax (Toggle Plain Text)
<?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é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érica Mockup - Software Libre Mé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>
Cheers,
Nav
Edit: Oops! I didn't see buddylee17's post. My internet is being weird !
Last edited by nav33n : Jul 11th, 2008 at 5:58 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- adware.mainsearch - how do you get rid of it? (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: PHP Script
- Next Thread: PHP/MySQL Update table from offline version to online version



Linear Mode