Posting form results on the SAME PAGE without using DATABASE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Posting form results on the SAME PAGE without using DATABASE

Post by tinoda »

greetings everybody, I need help on how to post form results ON THE SAME PAGE using php so that the form will permanently disappear and the results posted to html table will stay the same even after refresh. I have managed to use this script below to post results on the embedded html table but when i click refresh after submitting form the html table reverts to the original table with empty cells]:

Code: Select all

 
<html>
<body><form action="myfile.php" method="get">
Name: <input type="text" name="name" />
Age: <input type="text" name="age"  />
<input type="submit"  />
</form>
</body>
</html>
 
<html>
<title>myfiel.php</title>
<body>
 <table border="1">
<tr>
<td>Welcome</td><td><?php echo $_GET["name"]; ?></td>
</tr>
<tr><td>You are </td><td><?php echo $_GET["age"]; ?> years old.</td></tr>
</table>
 
 
</body>
</html>
Thank you in advance for your help
Last edited by tinoda on Mon Dec 29, 2008 5:13 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Posting form results on the SAME PAGE without using DATABASE

Post by requinix »

Bunch of ways of doing that. Simplest is to use GET instead of POST.
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Re: Posting form results on the SAME PAGE without using DATABASE

Post by tinoda »

Hie tasairis, thanks for your reply, I hv also used the get instead of post but nothing happens. It does post the result but if u refresh the browser everything resets to the original.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Posting form results on the SAME PAGE without using DATABASE

Post by papa »

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

Should be

<form action="nameofmypage.php" method="get">
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Re: Posting form results on the SAME PAGE without using DATABASE

Post by tinoda »

hie papa, thanks a span for your reply. I hv changed that as well and it successfully posted the results in the html table. But if i refresh the web browser it takes me to the start again. I need a system whereby if a user enters their name and age as indicated in the script then their results will be displayed permanently on the html table even if somebody refreshes the browser
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Posting form results on the SAME PAGE without using DATABASE

Post by papa »

Works for me:

<form action="test.php" method="get">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

<table border="1">
<tr>
<td>Welcome</td><td><?php echo $_GET["name"]; ?></td>
</tr>
<tr><td>You are </td><td><?php echo $_GET["age"]; ?> years old.</td></tr>
</table>

When posting this form the url will be:
http://localhost/test/test.php?name=test&age=12

And when refreshing the url stays the same.
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Re: Posting form results on the SAME PAGE without using DATABASE

Post by tinoda »

hie papa.

my url stays the same as well but it clears the content in the following cells:

<td>Welcome</td><td><?php echo $_GET["name"]; ?></td>
</tr>
<tr><td>You are </td><td><?php echo $_GET["age"]; ?> years old.</td
Post Reply