worldcomingtoanend Posted December 29, 2008 Share Posted December 29, 2008 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> Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/ Share on other sites More sharing options...
redarrow Posted December 29, 2008 Share Posted December 29, 2008 <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; } ?> Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725259 Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 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) Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725264 Share on other sites More sharing options...
redarrow Posted December 29, 2008 Share Posted December 29, 2008 wants to go even better use session and cookie ... To be honest as what i can see he learning i think. Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725267 Share on other sites More sharing options...
worldcomingtoanend Posted December 29, 2008 Author Share Posted December 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725274 Share on other sites More sharing options...
worldcomingtoanend Posted December 29, 2008 Author Share Posted December 29, 2008 <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. Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725276 Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725277 Share on other sites More sharing options...
worldcomingtoanend Posted December 29, 2008 Author Share Posted December 29, 2008 thank you Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725279 Share on other sites More sharing options...
redarrow Posted December 29, 2008 Share Posted December 29, 2008 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> Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725296 Share on other sites More sharing options...
worldcomingtoanend Posted December 29, 2008 Author Share Posted December 29, 2008 red arrow: its now even worse i am trying to play around with sessions may it can get to do. Link to comment https://forums.phpfreaks.com/topic/138720-posting-form-results-on-the-same-page-without-using-database/#findComment-725299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.