html - PHP collecting user input and displaying it -


so have basic program allows collect user input , output user or in other words display in browser lets delete object onclick method. simple todo list.

my problem how collect information , display each previous information in rows on page instead of going away when browser refreshed. know ideal database i'm trying keep simple , knowledge of databases far inadequate. feel php or javascript can resolve issue not clicking me. maybe loop or while loop job not sure, use help. thanks.

<?php if (isset($_post["user"])) {     $user_info = $_post["user"]; } ?> <!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>manage todos</title> </head> <body>      <form action="" method="post">          <input type="text" name="user"></input>         <input type="submit" value="post">       </form>      <h1><a href="#" onclick="remove(this)"><?php echo $user_info;?> <?php echo $collect; ?></a></h1>   </body> </html> 

you should use session store previous variable in order displayed again when page refreshed.

change code below : if (isset($_post["user"])) { $_session["user_info"] = $_post["user"]; }

also change <h1> below :

<h1><a href="#" onclick="remove(this)"><?php if (isset($_session["user_info"])) echo $_session["user_info"]; ?></a></h1> 

or change <h1> :

<?php   if (isset( $_session["user_info"])) { ?>     <h1><a href="#" onclick="remove(this)"><?php echo $_session["user_info"]; ?></a></h1> <?php   } ?> 

hopefully help.


update

sorry, forgot tell should start session first. here right code :

<?php session_start(); if (isset($_post["user"])) {     $_session["user_info"] = $_post["user"]; } ?> 

update 2

assuming url site 015_session_variable.php.

change code :

<?php     session_start();     if (isset($_post["user"])) {         $_session["old_user_info"] = isset($_session["new_user_info"]) ? $_session["new_user_info"] : "";         $_session["new_user_info"] = $_post["user"];     }     if (isset($_get["remove"])) {         if ($_get["remove"] == "new")             $_session["new_user_info"] = "";         else              $_session["old_user_info"] = "";     } ?> <!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>manage todos</title> </head> <body>      <form action="015_session_variable.php" method="post">         <input type="text" name="user" required></input>         <input type="submit" value="post">     </form>  <?php     if (isset($_session["new_user_info"]) && $_session["new_user_info"] != "") { ?>     <h1><a href="#" onclick="removeme('new');" title="remove me">latest user : <?php echo $_session["new_user_info"]; ?></a></h1> <?php     } ?>  <?php     if (isset($_session["old_user_info"]) && $_session["old_user_info"] != "") { ?>     <h1><a href="#" onclick="removeme('old');" title="remove me">previous user : <?php echo $_session["old_user_info"]; ?></a></h1> <?php     } ?>     <script>         function removeme(a) {             window.open('015_session_variable.php?remove=' + a, '_self');         }     </script> </body> </html> 

now have information :

  1. how create session
  2. how store variables in session
  3. how modify session's variables

basically need in code. utilize them imaginable possible. luck.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -