i have a textbox and a button,like this:

<form method='post' action=<?php echo $_SERVER["PHP_SELF"]; ?> >
<input type='text' name='write'>
</input>
<input type='submit' name='push'>
</input>
</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:

<?php
if(isset($_POST['push']))
if($_POST['push']) echo $_POST['write']."<br/>";
?>

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

cheers

You could store it in a variable so:

<?php
    if(isset($_POST['push']))
    {
         $text .= $_POST['write'];
         echo($text);
    }
?>

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.

i stored the variable in a file:

<?php
$filename='test.txt';
$handle=fopen($filename,'a');
$handle2=fopen($filename, 'rt');
if(isset($_POST['push']))
{
   fwrite($handle,$_POST['write'].' ');
   $contents=fread($handle2,filesize($filename));
   echo $contents;      
}
?>

,but i'm still hoping to find a more elegant solution :S

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

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.