php - How preserve my inputs values each time that I refresh my page? -


i want enter name , mark. mark entered less or equal 100, names , marks entered stored in associative array when click submit button , should request me enter name , marks. if enter mark greater 100 discarding name entered, when click submit button, php script should display me names , marks entered. here have done not getting desired results. please help. code:

<?php   if(isset($_post['lname']) && isset($_post['marks'])){          $name  = $_post['lname']; $marks = $_post['marks'];  $lists = array($name => $marks); foreach($lists $name => $marks){     echo $name . '<br>';     echo $marks;  } }   ?>  <form action = "<?php echo $_server['php_self'];?>" method = "post">  name:<br> <input type = "text" name = "lname"><br><br> marks:<br> <input type = "text" name = "marks"><br><br> <input type = "submit" value = "submit">  </form> 

you can use session achieve want, see code:

<?php   session_start();  if(isset($_post['lname']) && isset($_post['marks'])){          if($_post['marks'] > 100) { $_session['info'][] = array($_post['lname'] => $_post['marks']); } }  if(isset($_session['info'])) { for($i = 0; $i < count($_session['info']); $i++) {   foreach($_session['info'][$i] $name => $marks){     echo '<p>' . $name . '<br>';     echo $marks . '</p>';  } }  } ?>  <form action = "<?php echo $_server['php_self'];?>" method = "post">  name:<br> <input type = "text" name = "lname"><br><br> marks:<br> <input type = "text" name = "marks"><br><br> <input type = "submit" value = "submit">  </form> 

you should read docs session:

http://php.net/manual/en/intro.session.php


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -