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

Posted on 2004-04-22
Last Modified: 2008-03-06

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.

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

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

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..
Question by:Hannibal_L

Accepted Solution

chrgary earned 43 total points
ID: 10887754
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.

Assisted Solution

carchitect earned 41 total points
ID: 10887762
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 forums

Assisted Solution

Uzaree earned 41 total points
ID: 10922501
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

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

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

print $subj;
print $msg;



Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Responsive Design Tools 6 38
PHP string issue 5 17
Setting Up Local Lan Web Server 1 16
showing numeric numbers 2 10
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now