depends on the case. If you want the user to stop along the way and maybe come back next time and finish it, then this is a good option. otherwise you can use the session to save your progress.
<?php session_start(); if(isset($_POST['name'])){ //store answers in session $new = (!empty($_SESSION['session_name']))? $_SESSION['session_name'].'|'.$_POST['name'] : $_POST['name']; //split session into an array $_SESSION['session_name'] = $new; } else if(isset($_POST['clear'])){ if(!empty($_SESSION['session_name'])){ unset($_SESSION['session_name']); echo "cleared"; } else echo "Nothing to Clear"; } if(!empty($_SESSION['session_name'])){ var_dump($_SESSION['session_name']); } //finish the procees here befor storing into database; //use foreach to itterate btw arrays and match anwers //$_SESSION['session_name'] = explode('|', $_SESSION['session_name']); //answer table $answers = array('a','b','c','d','e'); /* foreach($_SESSION['session_name'] as $key => $ans){ if($ans == $answer[$key]){ //right procesesor } else{ //wrong procesesor } } */ //handle the right and wrong process get to total score the store in db ?> <form method="post" action="index.php"> <input name="name" type="text" placeholder=""> <input type="submit" value="submit"> </form> <form method="post" action="index.php"> <input type="submit" name="clear" value="clear"> </form>
SIMPLICITY BASIC demonstration of how a session can complete a task without a db request each time.
source share