Page 1 of 1
Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 3:46 am
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
Re: Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 4:36 am
by requinix
Bunch of ways of doing that. Simplest is to use GET instead of POST.
Re: Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 4:46 am
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.
Re: Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 4:56 am
by papa
<form action="get" method="post">
Should be
<form action="nameofmypage.php" method="get">
Re: Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 5:09 am
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
Re: Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 5:13 am
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.
Re: Posting form results on the SAME PAGE without using DATABASE
Posted: Mon Dec 29, 2008 5:17 am
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