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 427,196 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 2,192 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: 456 | Replies: 5 | Solved
Reply
Join Date: Mar 2008
Posts: 10
Reputation: soultrav is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
soultrav soultrav is offline Offline
Newbie Poster

echo when pushing button

  #1  
Mar 15th, 2008
i have a textbox and a button,like this:
  1. <form method='post' action=<?php echo $_SERVER["PHP_SELF"]; ?> >
  2. <input type='text' name='write'>
  3. </input>
  4. <input type='submit' name='push'>
  5. </input>
  6. </form>

, and i want that everytime that i push the button the content to be listed on the page without the previous content being lost. I know that something like:
  1. <?php
  2. if(isset($_POST['push']))
  3. if($_POST['push']) echo $_POST['write']."<br/>";
  4. ?>

would be useless because it would erase the previous text, but how can i get it done?

cheers
Last edited by soultrav : Mar 15th, 2008 at 6:52 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Perth, Australia
Posts: 119
Reputation: Auzzie is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Auzzie Auzzie is offline Offline
Junior Poster

Re: echo when pushing button

  #2  
Mar 15th, 2008
You could store it in a variable so:

  1. <?php
  2. if(isset($_POST['push']))
  3. {
  4. $text .= $_POST['write'];
  5. echo($text);
  6. }
  7. ?>
Reply With Quote  
Join Date: Mar 2008
Posts: 10
Reputation: soultrav is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
soultrav soultrav is offline Offline
Newbie Poster

Re: echo when pushing button

  #3  
Mar 15th, 2008
nope, that still doesn't works. I want that if I enter consecutevely 'a','b' and 'c' for example, the output to be:
a
b
c

The problem is that everytime i push the button the script reruns and the previous information gets lost.
Reply With Quote  
Join Date: Mar 2008
Posts: 10
Reputation: soultrav is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
soultrav soultrav is offline Offline
Newbie Poster

Re: echo when pushing button

  #4  
Mar 15th, 2008
i stored the variable in a file:

  1. <?php
  2. $filename='test.txt';
  3. $handle=fopen($filename,'a');
  4. $handle2=fopen($filename, 'rt');
  5. if(isset($_POST['push']))
  6. {
  7. fwrite($handle,$_POST['write'].' ');
  8. $contents=fread($handle2,filesize($filename));
  9. echo $contents;
  10. }
  11. ?>

,but i'm still hoping to find a more elegant solution
Reply With Quote  
Join Date: Mar 2008
Posts: 153
Reputation: Suomedia is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: echo when pushing button

  #5  
Mar 15th, 2008
Try this:

<?php

  session_start();

  if(isset($_POST['write'])) $push_result = $_SESSION['push_stuff'] . $_POST['write'] . '<br />';
	 
  $_SESSION['push_stuff'] = $push_result;

  echo $_SESSION['push_stuff'];

?>


Matti Ressler
Suomedia
Reply With Quote  
Join Date: Mar 2008
Posts: 10
Reputation: soultrav is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
soultrav soultrav is offline Offline
Newbie Poster

Re: echo when pushing button

  #6  
Mar 17th, 2008
Originally Posted by Suomedia View Post
Try this:

<?php

  session_start();

  if(isset($_POST['write'])) $push_result = $_SESSION['push_stuff'] . $_POST['write'] . '<br />';
	 
  $_SESSION['push_stuff'] = $push_result;

  echo $_SESSION['push_stuff'];

?>


Matti Ressler
Suomedia


yeah, that worked for me
thanks
Last edited by soultrav : Mar 17th, 2008 at 7:27 am.
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

Other Threads in the PHP Forum

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