doutu2017 2019-05-03 15:30
浏览 38

将测验结果保存到数据库

I have created a multiple choice quiz/questionnaire. The questions and answers are pulling from the database and I have sessions setup on the webpage. At the minute the user can only print the webpage when they get their results.

I am using phpmyadmin and php for the quiz. I am currently pulling from one database table called questions with the fields, questionID, question, ansYes and ansNo.

<?
//Always start this first
session_start();
include ("dbConnect.php");

if ( isset( $_SESSION['user_email'] ) ) {
     //Grab user data from the database using user email

} else {
   // Redirect them to the login page
    header("login.php");
}
$sql = "SELECT * FROM questions";
$dbQuery = $db->prepare($sql);
$dbQuery->execute();
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>List</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

  <style>


/* CSS animation */

@-webkit-keyframes fadeIn {
    0% { 
        opacity:0; 
        transform: scale(0.6);
    }

    100% {
        opacity:100%;
        transform: scale(1);
    }
}

@keyframes fadeIn {
    0% { opacity:0; }
    100% { opacity:100%; }
}  
  </style>

 <?php include("navIn.php"); ?>


<body>

<div class="container-fluid">
    <br>

<?php

    /*Printing out questions*/

    if(!isset($_POST["submitForm"])) {
        echo "<form method='post' action='checklist.php'>";

       if (isset($_SESSION["first_name"])) {
            echo '<span style="color:#000000;position:left; left:1060px;">Hello '.$_SESSION["first_name"].'!<br></span>';
       }
        while($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {


           echo"<div class=container-fluid text-center>";
            echo "<h4>" . $dbRow["question"] . "</h4>";
            echo "<h4><input type='radio' required name='" . $dbRow["questionID"] . "' value='Yes'> Yes <br></h4?";
            echo "<h4><input type='radio' required name='" . $dbRow["questionID"] . "' value='No'> No <br><br></h4>";
            echo "</div>";

        }
        echo "<input type='submit' name='submitForm' value='Submit'>";
        echo "</form>";

        echo"</div>";


    } else {

        if (isset($_SESSION["first_name"])) {
            echo '<span style="color:#000000;position:left; left:1060px;">Hello '.$_SESSION["first_name"].'!<br></span>';
       }
        /*printing out results from questions */
        echo"<div class=container-fluid text-center>";
        while($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
            if($_POST[$dbRow["questionID"]] == "Yes") {
                 echo '<h4 span style="color:blue;"> '.$dbRow["question"].'</span>';
                /*echo "<h4>" .$dbRow["question"]."<br></h4><br>";*/
                echo "<h4>" . $dbRow["ansYes"] . "</h4><br>";
            } else {
                echo '<h4 span style="color:blue;"> '.$dbRow["question"].'</span>';
         /*       echo "<h4>" .$dbRow["question"]."<br></h4><br>";*/
                echo "<h4>" . $dbRow["ansNo"] . "</h4><br>";


            }


        }
          echo"Click the button bellow to print this page!";
        echo'<br><form> <input type=button value="Print me!" onClick="javascript:window.print()"> </form>';
    echo"</div>";
    }

        ?>

</div>
</body>
 <?php include ("footer.php"); ?>
</html>

I would like to be able to save the users results so anytime they access checklist.php their results are there instead of having to print the page out.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
    • ¥20 怎么在stm32门禁成品上增加查询记录功能
    • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
    • ¥50 NT4.0系统 STOP:0X0000007B
    • ¥15 想问一下stata17中这段代码哪里有问题呀
    • ¥15 flink cdc无法实时同步mysql数据
    • ¥100 有人会搭建GPT-J-6B框架吗?有偿