Jump to content

Posting form results on the SAME PAGE without using DATABASE


worldcomingtoanend

Recommended Posts

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:

 

<html>

<body><form action="get" 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>

 

 

</body>

</html>

<html>
<body><form action=" " method="POST">
Name: <input type="text" name="name" />
Age: <input type="text" name="age"  />
<input type="submit" name="submit"/>
</form>

<?php if($_POST['submit']) {

$name=$_POST['name'];
$age=$_POST['age'];

echo " <table border='1'>
<tr>
<td>
Welcome
</td>
<td> 
$name 
</td>
</tr>
<tr>
<td>
You are
</td>
<td>
$age years old.
</td>
</tr>
</table>
</body>
</html>";
exit;
}
?>

The closest you can get to permanently displaying is using a cookie unless this is a page accessed by a user managed page where information can be stored in a database (or somewhere similar)

 

hie Gevans

 

i have tried the method posted by the poster before u.  all it does is display the table after click submit but if u refresh browser it disappears.  Yes I am new to php and i have loved php.  I hope u guys who have an experience will help me out.  by standing on your shoulders i know i willbe an expert one day.  so how do i use cookies, etc

<html>
<body><form action=" " method="POST">
Name: <input type="text" name="name" />
Age: <input type="text" name="age"  />
<input type="submit" name="submit"/>
</form>

<?php if($_POST['submit']) {

$name=$_POST['name'];
$age=$_POST['age'];

echo " <table border='1'>
<tr>
<td>
Welcome
</td>
<td> 
$name 
</td>
</tr>
<tr>
<td>
You are
</td>
<td>
$age years old.
</td>
</tr>
</table>
</body>
</html>";
exit;
}
?>

 

hie redarrow,thanks for helping me. i hv tried your code above.  From what i see its not really different from mine.  all it does is display a table after you click submit but if u refresh the browser it clears the table.

If you're interested in learning about cookies (other than just us telling you what to do with it)

 

check out the php reference here

 

And have a play around with it and see what it does.

 

Then if you still have issues with it let us know and we'll better show you how to implement it with your page

sorry had the code in the wrong order.

 


<?php if($_POST['submit']) {

$name=$_POST['name'];
$age=$_POST['age'];

echo " <table border='1'>
<tr>
<td>
Welcome
</td>
<td> 
$name 
</td>
</tr>
<tr>
<td>
You are
</td>
<td>
$age years old.
</td>
</tr>
</table>
</body>
</html>";

exit;
}
?>



<html>
<body><form action=" " method="POST">
Name: <input type="text" name="name" />
Age: <input type="text" name="age"  />
<input type="submit" name="submit"/>
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.