User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2008
Posts: 4
Reputation: vaish.rajan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vaish.rajan vaish.rajan is offline Offline
Newbie Poster

UPDATING TEXT AREA using PHP !!

  #1  
Jul 11th, 2008
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 ..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: UPDATING TEXT AREA using PHP !!

  #2  
Jul 11th, 2008
Then you need another form in the block of "edit".
  1. 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 [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*
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 398
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 78
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: UPDATING TEXT AREA using PHP !!

  #3  
Jul 11th, 2008
You should be placing the variable in between the textarea tags with a conditional:
  1. <textarea id='userInput' name="textspace" value="" cols="40" rows="3" >
  2. <?php
  3. if(isset($_POST)){
  4. echo $textspace;
  5. }
  6. ?>
  7. </textarea>
and for the edit, you've just got to read the file and assign it to a variable:
  1. if ($_POST['edit']){
  2. $myFile = "testFile.txt";
  3. $fh = fopen($myFile, 'r');
  4. if(filesize($myFile)!=0)
  5. {
  6. $textspace = fread($fh, filesize($myFile));
  7. }
  8. else
  9. {
  10. $textspace= "The file is empty";
  11. }
  12. fclose($fh);
  13. }
Reply With Quote  
Join Date: Jul 2008
Posts: 4
Reputation: vaish.rajan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vaish.rajan vaish.rajan is offline Offline
Newbie Poster

Re: UPDATING TEXT AREA using PHP !!

  #4  
Jul 11th, 2008
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 !!
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 398
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 78
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: UPDATING TEXT AREA using PHP !!

  #5  
Jul 11th, 2008
This is the file that I have working:
  1. <?php
  2. if ($_POST['save'])
  3. {
  4. $space = $_POST['textspace'];
  5. $myFile = "testFile.txt";
  6. $fh = fopen($myFile, 'w') or die("can't open file");
  7.  
  8. fwrite($fh, $space);
  9.  
  10. fclose($fh);
  11. echo "Saved";
  12. }
  13. if ($_POST['edit']){
  14. $myFile = "testFile.txt";
  15. $fh = fopen($myFile, 'r');
  16. if(filesize($myFile)!=0)
  17. {
  18. $textspace = fread($fh, filesize($myFile));
  19. }
  20. else
  21. {
  22. $textspace = "The file is empty";
  23. }
  24. fclose($fh);
  25. }
  26. if ($_POST['show'])
  27. {
  28. $myFile = "testFile.txt";
  29. $fh = fopen($myFile, 'r');
  30. if(filesize($myFile)!=0)
  31. {
  32. $theData = fread($fh, filesize($myFile));
  33. }
  34. else
  35. {
  36. echo "The file is empty";
  37. }
  38. fclose($fh);
  39. echo $theData;
  40. }
  41. ?>
  42. <form action="notesx.php" method="post">
  43. <fieldset>
  44. <legend>
  45. Capítulo 01:
  46. </legend>
  47. <textarea id='userInput' name="textspace" value="" cols="40" rows="3" >
  48. <?php
  49. if(isset($_POST['edit'])){
  50. echo $textspace;
  51. }
  52. ?>
  53. </textarea>
  54. <br>
  55. <input type="submit" name="save" value='save'/>
  56. <input type="submit" name="edit" value='edit'/>
  57. <input type="submit" name="show" value='show'/>
  58.  
  59. <br>
  60. <p><b id='boldStuff2'></b> </p>
  61.  
  62. </fieldset>
  63. </form>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: UPDATING TEXT AREA using PHP !!

  #6  
Jul 11th, 2008
Try this.
  1. <?php
  2. if ($_POST['save']) {
  3. $space = $_POST['textspace'];
  4. $myFile = "testFile.txt";
  5. $fh = fopen($myFile, 'w') or die("can't open file");
  6. fwrite($fh, $space);
  7. fclose($fh);
  8. echo "Saved";
  9. }
  10. if ($_POST['edit']) {
  11. $myFile = "testFile.txt";
  12. $fh = fopen($myFile, 'r');
  13. if(filesize($myFile)!=0) {
  14. $textspace= fread($fh, filesize($myFile));
  15. } else {
  16. $textspace= "The file is empty";
  17. }
  18. fclose($fh);
  19. }
  20. if ($_POST['show']) {
  21. $myFile = "testFile.txt";
  22. $fh = fopen($myFile, 'r');
  23. if(filesize($myFile)!=0) {
  24. $theData = fread($fh, filesize($myFile));
  25. } else {
  26. echo "The file is empty";
  27. }
  28. fclose($fh);
  29. echo $theData;
  30. }
  31. ?>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
  36. <title>atlas Am&eacute;rica (mockup) - Temario</title>
  37. <link rel="stylesheet" type="text/css" href="../../lib/css/contacto.css" />
  38. <link rel="alternate stylesheet" type="text/css" href="css/print.css" title="Print" />
  39. <link rel="icon" href="../../imgs/notes.ico" />
  40. <link rel="shortcut icon" href="../../imgs/notes.ico" type="image/x-icon" />
  41. </head>
  42.  
  43. <body>
  44. <div id="everything">
  45. <div id="header">
  46. <a href="../base.htm"><img src="../../imgs/banner-small.png" alt="atlas America v0.1 (mockup)" /></a>
  47. <h1><a href="base.htm">atlas America v0.1 (mockup) </a></h1>
  48. <ul>
  49. <li id="last"><a href="../../html/base.htm"><font size="2"></>Indice de temas</font></a></li>
  50. <li id="last"><a id="first" href="../index.htm">Salir</a></li>
  51. </ul>
  52.  
  53. </div>
  54. <div id="sidenav-content">
  55.  
  56. <br clear="all" />
  57.  
  58. <div id="imgizq">
  59. <img src="../../imgs/juanIndice2.png" />
  60. </div>
  61.  
  62. <div id="indice">
  63. <h1>Notas</h1>
  64. <form action="notesx.php" method="post">
  65. <fieldset>
  66. <legend>
  67. Capítulo 01:
  68. </legend>
  69. <textarea id='userInput' name="textspace" cols="40" rows="3" >
  70. <?php if(!empty($textspace)) { echo $textspace; } ?>
  71. </textarea>
  72. <br>
  73. <input type="submit" name="save" value='save'/>
  74. <input type="submit" name="edit" value='edit'/>
  75. <input type="submit" name="show" value='show'/>
  76.  
  77. <br>
  78. <p><b id='boldStuff2'></b> </p>
  79.  
  80. </fieldset>
  81. </form>
  82.  
  83. </div>
  84.  
  85. </div>
  86.  
  87.  
  88. <br clear="all" />
  89.  
  90.  
  91.  
  92. <div id="footer">atlas Am&eacute;rica Mockup - Software Libre M&eacute;xico</div>
  93.  
  94.  
  95. </div>
  96. <p>
  97. <a href="http://validator.w3.org/check?uri=referer"><img
  98. src="http://www.w3.org/Icons/valid-xhtml10"
  99. alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>
  100. </p>
  101. </body>
  102. </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 !
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*
Reply With Quote  
Join Date: Jul 2008
Posts: 4
Reputation: vaish.rajan is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vaish.rajan vaish.rajan is offline Offline
Newbie Poster

Re: UPDATING TEXT AREA using PHP !!

  #7  
Jul 11th, 2008
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 !
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 10:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC