How to ouput form information on same (form) page?

Hello,

I am wondering if (then how) it is possible to output data received from a form on the same page as form, and also to for every new input in the form, to lineup the datas below each other.

What I am trying to say is that I would like the site to have the functionality as a "Guest book-site" or as a "Forum"  where the visitor can just leave a message and see what others before them have written.

Ex:
*****************************************************
echo "<form action='thispage.php' method='post'>":
//some input fields     ...<input .....name=subject> ....
//.....<input.....name=message> .....
// ...etc ...
echo "</form>";

// here the information inputed in the form should be output ::
$subj = $_POST["subject"];
$msg = $_POST["message"];
etc....

*****************************************************
So, for every new entry in the form (by same or different user) the inputed data should be outputed just below the form.
And so is should lineup every new entry below each other, without overwriting the previous data !!

And I don't want to wirte the form data down to file and then read the data back to the site for every entry because that would be unneccesary .....I think

I hope you got what I meant..
Hannibal_LAsked:
Who is Participating?
 
chrgaryCommented:
I think I understand what you mean, and this would be possible for each individual user to see their own comments using cookies or sessions perhaps, but other visitors that visit the page will not be able to see the comments of other visitors without them being written to a database or text file.  The only variables that everyone can see are $_server and $_env variables, which unfortunately only the webserver and php namespace write to.

Your best bet would probably be to store them in a database, since having a textfile marked as readable and writable might compromise the security since you have to set that file as readable and writable on your webserver, unless you place it outside of the webroot directory.
0
 
carchitectCommented:
simple either use some file handling ......

//Form Code
<Any data submitted to form shud be appeneded to the file>
//Form closed

//Display file

It is just like this page (experts exchnage)

or use some database...submit data in it ....and display after form...like forums
0
 
UzareeCommented:
All you need to do is remove the

"<form action='thispage.php' method='post'>

and change it to

"<form action='' method='post'>

that will cause the form to post to itself

so now you would have

Ex:
*****************************************************
echo "<form name='form' method='post'>":
//some input fields     ...<input .....name=subject> ....
//.....<input.....name=message> .....
// ...etc ...
echo "</form>";

// here the information inputed in the form should be output ::
$subj = $_POST["subject"];
$msg = $_POST["message"];

print $subj;
print $msg;

etc....

*****************************************************
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.