php - how do i call the previous page's random value to another page? -


guys main page

<?php $random = rand(4, 5); $random2 = rand(1, 12); $random3 = rand(1, 60); $random4 = rand(1, 60); $random5 = rand(1, 60);  if ($random2 % 4 != 0) { $random2 += 4 - ($random2 % 4); $call = $random; } else { $random2 += 4 - ($random2 % 4); $call = $random2; }  $answer = $random * $random2; ?>  <html> <head>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">     <link rel="stylesheet" href="css/main.css" type="text/css"/>     <link rel="stylesheet" href="css/easy2.css" type="text/css"/>      <title> easy game 2 </title> <center>     <h1> easy game 2 </h1>     <h2> multiple choice! </h2>     <div class="border_solid">         <div id="timer"></div>     </div>     <hr> </center> </head> <body> <form method="post" action="doeasygame2.php">     <table cellspacing="40" class="table">         <tr>             <td>                 <label for="question_1"><?php echo $random; ?> x <?php echo $random2; ?> =?</label>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>"><?php echo $random3; ?>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>"><?php echo $random4; ?>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>"><?php echo $random5; ?>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $answer; ?>"><?php echo $answer; ?>             </td>             <td>                 <input type="submit" class="submit" value="submit" name="submit"/><br>             </td>         </tr>     </table> </form> </body> <script type="text/javascript"> var myvar = setinterval(function () {     mytimer() }, 1000); var d = 0;  function mytimer() {     document.getelementbyid("timer").innerhtml = d++; }  </script> </html> 

and page check easygame page after user has clicked on radio buttons he/she selected on each question,it bring dopage verify if he/she's answer he/she's submitted correct or wrong.

<?php  $random = isset($_post['random']) ? intval($_post['random']) : 0; $random2 = isset($_post['random2']) ? intval($_post['random2']) : 0; $random3 = isset($_post['random3'])? intval($_post['random3']) : 0; $random4 = isset($_post['random4'])? intval($_post['random4']) : 0; $random5 = isset($_post['random5'])? intval($_post['random5']) : 0; $answer = isset($_post['answer'])? intval($_post['answer']) : 0; $mcq = $_post['mcq']; ?>  <html> <head>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">     <link rel="stylesheet" href="css/main.css" type="text/css"/>     <link rel="stylesheet" href="css/easy2.css" type="text/css"/>      <title> easy game 2 </title> <center>     <h1> easy game 2 </h1>     <h2> multiple choice! </h2>     <hr> </center> </head> <body> <table cellspacing="40" class="table">     <tr>         <td>             <label for="question_1"><?php echo $random; ?> x <?php echo $random2; ?> =?</label>             <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>"><?php echo $random3; ?>             <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>"><?php echo $random4; ?>             <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>"><?php echo $random5; ?>             <input type="radio" id="mcq" name="mcq"><?php echo $answer; ?>             <?php             if ($mcq == $answer) {                 echo "correct!";             } else {                 echo "wrong!";             }             ?>         </td>     </tr> </table> </body> </html> 

why when click on radio button first page , submit it, values on next page 0 , answer validated wrong?

i have reviewed code , found have not storing options in first page , when trying post on next page become 0 because radio button have same name , when post on next page post selected radio value.

for fulfill requirement need use below code first page:

<?php $random = rand(4, 5); $random2 = rand(1, 12); $random3 = rand(1, 60); $random4 = rand(1, 60); $random5 = rand(1, 60);  if ($random2 % 4 != 0) { $random2 += 4 - ($random2 % 4); $call = $random; } else { $random2 += 4 - ($random2 % 4); $call = $random2; }  $answer = $random * $random2; ?>  <html> <head>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">     <link rel="stylesheet" href="css/main.css" type="text/css"/>     <link rel="stylesheet" href="css/easy2.css" type="text/css"/>      <title> easy game 2 </title> <center>     <h1> easy game 2 </h1>     <h2> multiple choice! </h2>     <div class="border_solid">         <div id="timer"></div>     </div>     <hr> </center> </head> <body> <form method="post" action="doeasygame2.php"> <table cellspacing="40" class="table">         <tr>             <td>                 <label for="question_1"><?php echo $random; ?> x <?php echo $random2; ?> =?</label>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>"><?php echo $random3; ?>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>"><?php echo $random4; ?>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>"><?php echo $random5; ?>                 <input type="radio" id="mcq" name="mcq" value="<?php echo $answer; ?>"><?php echo $answer; ?>             </td>             <td>                 <input type="submit" class="submit" value="submit" name="submit"/><br>             </td>         </tr>     </table>     <input type="hidden" name="random" value="<?php print $random ?>">     <input type="hidden" name="random2" value="<?php print $random2 ?>">     <input type="hidden" name="random3" value="<?php print $random3 ?>">     <input type="hidden" name="random4" value="<?php print $random4 ?>">     <input type="hidden" name="random5" value="<?php print $random5 ?>">     <input type="hidden" name="answer" value="<?php print $answer ?>"> </form> </body> <script type="text/javascript"> var myvar = setinterval(function () {     mytimer() }, 1000); var d = 0;  function mytimer() {     document.getelementbyid("timer").innerhtml = d++; }  </script> </html> 

please use below code second page:

<?php  $random = isset($_post['random']) ? intval($_post['random']) : 0; $random2 = isset($_post['random2']) ? intval($_post['random2']) : 0; $random3 = isset($_post['random3'])? intval($_post['random3']) : 0; $random4 = isset($_post['random4'])? intval($_post['random4']) : 0; $random5 = isset($_post['random5'])? intval($_post['random5']) : 0; $answer = isset($_post['answer'])? intval($_post['answer']) : 0; $mcq = $_post['mcq']; ?>  <html> <head>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">     <link rel="stylesheet" href="css/main.css" type="text/css"/>     <link rel="stylesheet" href="css/easy2.css" type="text/css"/>      <title> easy game 2 </title> <center>     <h1> easy game 2 </h1>     <h2> multiple choice! </h2>     <hr> </center> </head> <body> <table cellspacing="40" class="table">     <tr>         <td>             <label for="question_1"><?php echo $random; ?> x <?php echo $random2; ?> =?</label>             <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>" <?php print $random3 == $mcq ? 'checked="checked"' : '' ?> ><?php echo $random3; ?>             <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>" <?php print $random4 == $mcq ? 'checked="checked"' : '' ?> ><?php echo $random4; ?>             <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>" <?php print $random5 == $mcq ? 'checked="checked"' : '' ?> ><?php echo $random5; ?>             <input type="radio" id="mcq" name="mcq" <?php print $mcq == $answer ? 'checked="checked"' : '' ?> ><?php echo $answer; ?>             <?php             if ($mcq == $answer) {                 echo "correct!";             } else {                 echo "wrong!";             }             ?>         </td>     </tr> </table> </body> </html> 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -