Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <?php
  2.  
  3. //Set question number
  4. $n=1;
  5. $number = $_GET['n'];
  6. //Get total number of questions
  7. $query = "select * from questions where questions_id=$number";
  8. $results = mysql_query($query) or die (mysql_error());
  9. $total= mysql_num_rows($results);
  10.  
  11. //Check if form was submitted
  12. if($_POST){
  13.  
  14. $number = $_POST['number'];
  15. $choice = $_POST['choice'];
  16. $next=$number+1;
  17. //Get total number of questions
  18.  
  19. $query = "SELECT * FROM questions ";
  20. $results = mysql_query($query) or die (mysql_error());
  21. $total = mysql_num_rows($results);
  22. //Get correct choice
  23.  
  24. $query="insert into stressselfassessment (choice,questions_id)
  25. values('$choice' , '$number' )";
  26. $insert_row= mysql_query($query) or die (mysql_error());
  27.  
  28. //VALIDATE INSERT
  29.  
  30. //compare answer with result
  31.  
  32. if($number == $total){
  33. header("Location: final.php");
  34. exit();
  35. } else {
  36. header("Location: question.php?n=".$next);
  37. }
  38.  
  39. }
  40.  
  41. ?>
  42.  
  43. <!DOCTYPE html>
  44. <html>
  45. <head>
  46. <meta charset="utf-8" />
  47. <title>Stress Assessment</title>
  48. <link rel="stylesheet" href="style.css" type="text/css" />
  49. </head>
  50. <body>
  51.  
  52. <div id="container">
  53. <header>
  54. <div class="container">
  55. <h1>Stress Assessment</h1>
  56. </div>
  57. </header>
  58.  
  59. <div class="container">
  60. <div class="current">Question <?php echo $number; ?> </div>
  61.  
  62. <form method="post" >
  63. <ul >
  64. <?php
  65.  
  66. $sqlquestions = "select question,questions_id, choice1, choice2,choice3, choice4 from questions where questions_id=$number";
  67.  
  68. $resques = mysql_query($sqlquestions) or die (mysql_error());
  69.  
  70. while($row = mysql_fetch_array($resques))
  71. {
  72. echo $row['question'];
  73.  
  74. ?>
  75.  
  76. <li><input name="choice" type="radio" value="<?php echo $row['choice1']; ?>" /><?php echo $row['choice1']; ?><br>
  77. <input type="hidden" name="choice7" value="1" >
  78. <input name="choice" type="radio" value="<?php echo $row['choice2']; ?>" /><?php echo $row['choice2']; ?><br>
  79. <input type="hidden" name="choice7" value="2" >
  80. <input name="choice" type="radio" value="<?php echo $row['choice3']; ?>" /><?php echo $row['choice3']; ?><br>
  81. <input type="hidden" name="choice7" value="3" >
  82. <input name="choice" type="radio" value="<?php echo $row['choice4']; ?>" /><?php echo $row['choice4']; ?><br>
  83. <input type="hidden" name="choice7" value="4" >
  84. </li>
  85. <?php
  86.  
  87. }
  88.  
  89. ?>
  90. </ul>
  91. <input type="submit" name="submit" value="Please Select" />
  92. <input type="hidden" name="number" value="<?php echo $number; ?>" />
  93. </form>
  94. </div>
  95. </div>
  96.  
  97. </body>
  98. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement