Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Set question number
- $n=1;
- $number = $_GET['n'];
- //Get total number of questions
- $query = "select * from questions where questions_id=$number";
- $results = mysql_query($query) or die (mysql_error());
- $total= mysql_num_rows($results);
- //Check if form was submitted
- if($_POST){
- $number = $_POST['number'];
- $choice = $_POST['choice'];
- $next=$number+1;
- //Get total number of questions
- $query = "SELECT * FROM questions ";
- $results = mysql_query($query) or die (mysql_error());
- $total = mysql_num_rows($results);
- //Get correct choice
- $query="insert into stressselfassessment (choice,questions_id)
- values('$choice' , '$number' )";
- $insert_row= mysql_query($query) or die (mysql_error());
- //VALIDATE INSERT
- //compare answer with result
- if($number == $total){
- header("Location: final.php");
- exit();
- } else {
- header("Location: question.php?n=".$next);
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Stress Assessment</title>
- <link rel="stylesheet" href="style.css" type="text/css" />
- </head>
- <body>
- <div id="container">
- <header>
- <div class="container">
- <h1>Stress Assessment</h1>
- </div>
- </header>
- <div class="container">
- <div class="current">Question <?php echo $number; ?> </div>
- <form method="post" >
- <ul >
- <?php
- $sqlquestions = "select question,questions_id, choice1, choice2,choice3, choice4 from questions where questions_id=$number";
- $resques = mysql_query($sqlquestions) or die (mysql_error());
- while($row = mysql_fetch_array($resques))
- {
- echo $row['question'];
- ?>
- <li><input name="choice" type="radio" value="<?php echo $row['choice1']; ?>" /><?php echo $row['choice1']; ?><br>
- <input type="hidden" name="choice7" value="1" >
- <input name="choice" type="radio" value="<?php echo $row['choice2']; ?>" /><?php echo $row['choice2']; ?><br>
- <input type="hidden" name="choice7" value="2" >
- <input name="choice" type="radio" value="<?php echo $row['choice3']; ?>" /><?php echo $row['choice3']; ?><br>
- <input type="hidden" name="choice7" value="3" >
- <input name="choice" type="radio" value="<?php echo $row['choice4']; ?>" /><?php echo $row['choice4']; ?><br>
- <input type="hidden" name="choice7" value="4" >
- </li>
- <?php
- }
- ?>
- </ul>
- <input type="submit" name="submit" value="Please Select" />
- <input type="hidden" name="number" value="<?php echo $number; ?>" />
- </form>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement