{"id":4939,"date":"2023-06-19T11:03:33","date_gmt":"2023-06-19T11:03:33","guid":{"rendered":"https:\/\/beproblemsolver.com\/?p=4939"},"modified":"2025-05-30T08:48:21","modified_gmt":"2025-05-30T08:48:21","slug":"online-quiz-system-in-php","status":"publish","type":"post","link":"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/","title":{"rendered":"Online Quiz System in PHP (with source code) in 2023"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/#Establish_Database\" >Establish Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/#Login_and_SignUp\" >Login and SignUp<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/#Dashboard_and_Quiz_Section\" >Dashboard and Quiz Section<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/#Logic_Part_of_Online_Quiz_System\" >Logic Part of Online Quiz System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/beproblemsolver.com\/online-quiz-system-in-php\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In today&#8217;s digital age, online quizzes have become a popular way to evaluate and assess knowledge. An online quiz system project in PHP offers numerous advantages over pen-and-paper tests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So in this blog post, we develop a PHP multiple choice Quiz source code project from scratch. No worry! We guide you through the whole process. We use PHP, a popular server-side scripting language, with a database built around <a href=\"https:\/\/www.mysql.com\/\" data-type=\"URL\" data-id=\"https:\/\/www.mysql.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And if you want to learn how to build a simple PHP cart, check out our <a href=\"https:\/\/beproblemsolver.com\/simple-php-shopping-cart-with-session\/\" data-type=\"URL\" data-id=\"https:\/\/beproblemsolver.com\/simple-php-shopping-cart-with-session\/\" target=\"_blank\" rel=\"noreferrer noopener\">article here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will code a fully functional online quiz system. Complete with a user-friendly interface powered by BootStrap 5. Hooked with MySQL database connectivity. Additionally, we will provide you with the complete source code for the project, which you can use as a basis for your own quiz system. Or customize it to meet your specific needs. Get faster loading with a VPS hosting<strong> <\/strong><a href=\"https:\/\/www.domainracer.com\/vps-hosting\/singapore\/\" target=\"_blank\" rel=\"noreferrer noopener\">server closer to your location<\/a><strong> <\/strong>using reduced latency and zero downtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our guide will help you build a robust and effective online quiz system in PHP.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Establish_Database\"><\/span>Establish Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We can use the GUI tool of <strong>phpMyAdmin<\/strong> to provide a user-friendly experience for managing the MySQL database named <strong>&#8220;quiz&#8221;<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this database, we create 3 main tables named:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>users<\/strong>: here we can track the login of different users.<\/li>\n\n\n\n<li><strong>questions<\/strong>: in this table, we enter questions for our quiz app.<\/li>\n\n\n\n<li><strong>answers<\/strong>: in this table, we will record our answers to questions linked with &#8220;<strong>ans_id&#8221;<\/strong>.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/be-problem-solver\/image\/upload\/v1685346799\/question-table-of-quiz-system_intlvv.webp\" alt=\"Question table of Quiz System\"\/><figcaption class=\"wp-element-caption\">Question Table of online quiz system<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/be-problem-solver\/image\/upload\/v1685346309\/Answer-table-of-Quiz-System_gvfplz.webp\" alt=\"Image of Answer table of Quiz System\"\/><figcaption class=\"wp-element-caption\">Answer table of Quiz System<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, using the GUI tool of phpMyAdmin provides a user-friendly experience for managing the MySQL database named <strong>&#8220;quiz&#8221;<\/strong>. Also, you can download this database file from the below link:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/be-problem-solver\/image\/upload\/v1682745603\/Quiz_System_in_MySQL_database_rj1oua.webp\" alt=\"image of MySQL database for our Online Quiz system\"\/><figcaption class=\"wp-element-caption\">MySQL database for our Online Quiz system<\/figcaption><\/figure>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/github.com\/PawanKumar-Dev\/simple-quiz-system-php-and-mysql\/tree\/main\/SQLFile\" target=\"_blank\" rel=\"noreferrer noopener\">Download Database<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Login_and_SignUp\"><\/span>Login and SignUp<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the code below for our login page which is an &#8220;<strong>index.php&#8221;<\/strong> file in our case. If you want details on how to follow step by step guide to building a custom login and signup functionality in PHP, then check out <a href=\"https:\/\/beproblemsolver.com\/user-login-in-php-with-session\/\" data-type=\"URL\" data-id=\"https:\/\/beproblemsolver.com\/user-login-in-php-with-session\/\" target=\"_blank\" rel=\"noreferrer noopener\">this article<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/be-problem-solver\/image\/upload\/v1682746664\/Login_UI_of_Quiz_System_m80hwr.webp\" alt=\"Online Quiz System Php source code\"\/><figcaption class=\"wp-element-caption\">UI design for Login Signup of Quiz System<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><strong><strong>index.php<\/strong><\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"monokai\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;?php\nrequire_once(\"connect.php\");\nrequire_once(\"function.php\");\nsession_start();\n\nif (isset($_SESSION['login_active'])) {\n  header(\"Location: dashboard.php\");\n  exit();\n} else {\n\n  if (isset($_POST['login'])) {\n    $email = santize($_POST['email']);\n    $inputpassword = santize($_POST['password']);\n    $password = md5($inputpassword);\n\n    $sql = \"SELECT * FROM users WHERE email = '$email' AND password = '$password'\";\n    $result = mysqli_query($conn, $sql);\n\n    if (mysqli_num_rows($result) > 0) {\n      while ($row = mysqli_fetch_assoc($result)) {\n        $_SESSION['login_active'] = [$row[\"name\"], $row[\"email\"]];\n        $_SESSION['msg'] = \"Welcome to Dashboard\";\n        $_SESSION['class'] = \"text-bg-success\";\n        header(\"Location: dashboard.php\");\n        exit();\n      }\n    } else {\n      $_SESSION['msg'] = \"Check Email &amp; Password\";\n      $_SESSION['class'] = \"text-bg-danger\";\n      header(\"Location: index.php\");\n      exit();\n    }\n  }\n}\n\n?>\n\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;title>Quiz Login&lt;\/title>\n  &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\">\n  &lt;link rel=\"stylesheet\" href=\"css\/style.css\">\n&lt;\/head>\n\n&lt;body>\n  &lt;section class=\"main-section\">\n    &lt;div class=\"container\">\n\n      &lt;?php if (isset($_SESSION['msg'])) : ?>\n        &lt;div class=\"toast-container position-fixed bottom-0 end-0 p-3\">\n          &lt;div class=\"toast fade show\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\">\n            &lt;div class=\"toast-header &lt;?php echo $_SESSION['class']; ?>\">\n              &lt;strong class=\"me-auto\">Message&lt;\/strong>\n              &lt;button type=\"button\" class=\"btn-close text-white\" data-bs-dismiss=\"toast\" aria-label=\"Close\">&lt;\/button>\n            &lt;\/div>\n            &lt;div class=\"toast-body\">\n              &lt;?php\n              $message = $_SESSION['msg'];\n              unset($_SESSION['msg']);\n              echo $message;\n              ?>\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;?php endif; ?>\n\n      &lt;div class=\"row justify-content-center align-items-center\" style=\"height:100vh;\">\n        &lt;div class=\"col-md-7 col-lg-4\">\n          &lt;div class=\"box rounded\">\n            &lt;div class=\"img\">&lt;\/div>\n            &lt;div class=\"login-box p-5\">\n              &lt;h2 class=\"pb-4\">Login&lt;\/h2>\n              &lt;form action=\"\" method=\"post\">\n                &lt;div class=\"mb-4\">\n                  &lt;input type=\"email\" class=\"form-control\" placeholder=\"Enter Email address\" name=\"email\">\n                &lt;\/div>\n                &lt;div class=\"mb-4\">\n                  &lt;input type=\"password\" class=\"form-control\" placeholder=\"Enter Password\" name=\"password\">\n                &lt;\/div>\n                &lt;div class=\"d-grid gap-2\">\n                  &lt;button type=\"submit\" class=\"btn btn-primary\" name=\"login\">Login&lt;\/button>\n                &lt;\/div>\n              &lt;\/form>\n\n              &lt;div class=\"py-4 text-center\">\n                Join now, &lt;a href=\"signup.php\" class=\"link\">Sign Up&lt;\/a>\n              &lt;\/div>\n\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;\/div>\n    &lt;\/div>\n  &lt;\/section>\n\n  &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/js\/bootstrap.bundle.min.js\">&lt;\/script>\n&lt;\/body>\n&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Below is the code for our signup page:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><strong>signup.php<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"monokai\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;?php\nrequire_once(\"connect.php\");\nrequire_once(\"function.php\");\nsession_start();\n\nif (isset($_POST['signup'])) {\n  $name = santize($_POST['name']);\n  $email = santize($_POST['email']);\n  $inputpassword = santize($_POST['password']);\n\n  $password = md5($inputpassword);\n\n  $sql = \"INSERT INTO users (name, email, password) VALUES ('$name', '$email', '$password');\";\n\n  if (mysqli_query($conn, $sql)) {\n    $_SESSION['msg'] = \"You have Signed Up Successfully\";\n    $_SESSION['class'] = \"text-bg-success\";\n    header(\"Location: index.php\");\n    exit();\n  } else {\n    $_SESSION['msg'] = \"Sign Up failed\";\n    $_SESSION['class'] = \"text-bg-danger\";\n    header(\"Location: index.php\");\n    exit();\n  }\n}\n?>\n\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;title>Quiz SignUp&lt;\/title>\n  &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\">\n  &lt;link rel=\"stylesheet\" href=\"css\/style.css\">\n&lt;\/head>\n\n&lt;body>\n  &lt;section class=\"main-section\">\n    &lt;div class=\"container\">\n      &lt;div class=\"row justify-content-center align-items-center\" style=\"height:100vh;\">\n        &lt;div class=\"col-md-7 col-lg-4\">\n          &lt;div class=\"box rounded\">\n            &lt;div class=\"img-2\">&lt;\/div>\n            &lt;div class=\"login-box p-5\">\n              &lt;h2 class=\"pb-4\">Sign Up&lt;\/h2>\n              &lt;form action=\"\" method=\"post\">\n                &lt;div class=\"mb-4\">\n                  &lt;input type=\"text\" class=\"form-control\" placeholder=\"Enter Name\" name=\"name\" required>\n                &lt;\/div>\n                &lt;div class=\"mb-4\">\n                  &lt;input type=\"email\" class=\"form-control\" placeholder=\"Enter Email address\" name=\"email\" required>\n                &lt;\/div>\n                &lt;div class=\"mb-4\">\n                  &lt;input type=\"password\" class=\"form-control\" placeholder=\"Enter Password\" name=\"password\" required>\n                &lt;\/div>\n                &lt;div class=\"d-grid gap-2\">\n                  &lt;button type=\"submit\" class=\"btn btn-primary-1\" name=\"signup\">Sign Up&lt;\/button>\n                &lt;\/div>\n              &lt;\/form>\n\n              &lt;div class=\"py-4 text-center\">\n                &lt;a href=\"index.php\" class=\"link\">Login&lt;\/a>\n              &lt;\/div>\n\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;\/div>\n    &lt;\/div>\n  &lt;\/section>\n\n  &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/js\/bootstrap.bundle.min.js\">&lt;\/script>\n&lt;\/body>\n&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s take a break and enjoy <a href=\"https:\/\/beproblemsolver.com\/top-16-best-isekai-anime-with-op-mcs\/\" data-type=\"link\" data-id=\"https:\/\/beproblemsolver.com\/top-16-best-isekai-anime-with-op-mcs\/\">16 isekai with OP MC in 2024<\/a>. Enjoy \ud83d\ude0e\ud83d\ude0e!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Dashboard_and_Quiz_Section\"><\/span>Dashboard and Quiz Section<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To create a dashboard for an online quiz system, we implement a set of features to manage the quiz questions and answers. Here are the steps to create a basic dashboard:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>dashboard.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"monokai\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;?php\nrequire_once(\"connect.php\");\nsession_start();\n\nif (!isset($_SESSION['login_active'])) {\n  header(\"Location: index.php\");\n  exit();\n}\n?>\n\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;title>Quiz Dashboard&lt;\/title>\n  &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\">\n  &lt;link rel=\"stylesheet\" href=\"css\/style.css\">\n&lt;\/head>\n\n&lt;body>\n  &lt;section class=\"main-section\">\n\n    &lt;nav class=\"navbar navbar-expand-lg bg-body-tertiary bg-dark\" data-bs-theme=\"dark\">\n      &lt;div class=\"container-fluid\">\n        &lt;a class=\"navbar-brand\" href=\"dashboard.php\">Quiz&lt;\/a>\n        &lt;button class=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarSupportedContent\">\n          &lt;span class=\"navbar-toggler-icon\">&lt;\/span>\n        &lt;\/button>\n        &lt;div class=\"collapse navbar-collapse\" id=\"navbarSupportedContent\">\n          &lt;ul class=\"navbar-nav me-auto mb-2 mb-lg-0\">\n            &lt;li class=\"nav-item\">\n              &lt;a class=\"nav-link active\" aria-current=\"page\" href=\"#\">Home&lt;\/a>\n            &lt;\/li>\n            &lt;li class=\"nav-item\">\n              &lt;a class=\"nav-link\" href=\"#\">Link&lt;\/a>\n            &lt;\/li>\n          &lt;\/ul>\n\n          &lt;div class=\"d-flex\">\n            &lt;a class=\"btn btn-danger\" href=\"logout.php\">Logout&lt;\/a>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;\/div>\n    &lt;\/nav>\n\n\n    &lt;div class=\"container\">\n\n      &lt;?php if (isset($_SESSION['msg'])) : ?>\n        &lt;div class=\"toast-container position-fixed bottom-0 end-0 p-3\">\n          &lt;div class=\"toast fade show\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\">\n            &lt;div class=\"toast-header &lt;?php echo $_SESSION['class']; ?>\">\n              &lt;strong class=\"me-auto\">Success&lt;\/strong>\n              &lt;button type=\"button\" class=\"btn-close text-white\" data-bs-dismiss=\"toast\" aria-label=\"Close\">&lt;\/button>\n            &lt;\/div>\n            &lt;div class=\"toast-body\">\n              &lt;?php\n              $message = $_SESSION['msg'];\n              unset($_SESSION['msg']);\n              echo $message;\n              ?>\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;?php endif; ?>\n\n      &lt;div class=\"row justify-content-center\">\n        &lt;h2 class=\"pt-4\">Welcome to Dashboard, &lt;?php echo $_SESSION['login_active']['0']; ?>&lt;\/h2>\n\n        &lt;div class=\"col-md-6\">\n          &lt;div class=\"card m-5 p-3\">\n            &lt;div class=\"card-body\">\n              &lt;h3 class=\"card-title py-2\">Start taking Quiz&lt;\/h3>\n              &lt;a href=\"quiz.php\" class=\"btn btn-warning m-2\">Start the Quiz&lt;\/a>\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;\/div>\n    &lt;\/div>\n  &lt;\/section>\n\n  &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/js\/bootstrap.bundle.min.js\">&lt;\/script>\n&lt;\/body>\n&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We use an HTML form where users can take the online quiz system. Our form display each question along with multiple-choice options. Users can select one option for each question. Here is our PHP script:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>quiz.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"monokai\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;?php\nrequire_once(\"connect.php\");\nrequire_once(\"function.php\");\nsession_start();\n\nif (!isset($_SESSION['login_active'])) {\n  header(\"Location: index.php\");\n  exit();\n}\n?>\n\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;title>Quiz&lt;\/title>\n  &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\">\n  &lt;link rel=\"stylesheet\" href=\"css\/style.css\">\n&lt;\/head>\n\n&lt;body>\n  &lt;section class=\"main-section\">\n\n    &lt;nav class=\"navbar navbar-expand-lg bg-body-tertiary bg-dark\" data-bs-theme=\"dark\">\n      &lt;div class=\"container-fluid\">\n        &lt;a class=\"navbar-brand\" href=\"dashboard.php\">Quiz&lt;\/a>\n        &lt;button class=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarSupportedContent\">\n          &lt;span class=\"navbar-toggler-icon\">&lt;\/span>\n        &lt;\/button>\n        &lt;div class=\"collapse navbar-collapse\" id=\"navbarSupportedContent\">\n          &lt;ul class=\"navbar-nav me-auto mb-2 mb-lg-0\">\n            &lt;li class=\"nav-item\">\n              &lt;a class=\"nav-link active\" aria-current=\"page\" href=\"dashboard.php\">Dashboard&lt;\/a>\n            &lt;\/li>\n          &lt;\/ul>\n\n          &lt;div class=\"d-flex\">\n            &lt;a class=\"btn btn-danger\" href=\"logout.php\">Logout&lt;\/a>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;\/div>\n    &lt;\/nav>\n\n    &lt;form action=\"checkanswers.php\" method=\"post\">\n      &lt;?php for ($i = 1; $i &lt;= totalquestion($conn); $i++) :\n        $sql = \"SELECT * FROM questions where qid = $i\";\n        $result = mysqli_query($conn, $sql);\n      ?>\n\n        &lt;div class=\"container\">\n          &lt;div class=\"row justify-content-center\">\n\n            &lt;?php while ($row = mysqli_fetch_assoc($result)) :\n              $sql = \"SELECT * FROM answers where ans_id = $i\";\n              $result = mysqli_query($conn, $sql);\n            ?>\n              &lt;div class=\"col-md-8\">\n                &lt;div class=\"card my-2 p-3\">\n                  &lt;div class=\"card-body\">\n                    &lt;h5 class=\"card-title py-2\">Q.&lt;?php echo $row['qid'] . \" \" . $row[\"question\"];; ?> &lt;\/h5>\n\n                    &lt;?php while ($row = mysqli_fetch_assoc($result)) : ?>\n                      &lt;div class=\"form-check\">\n                        &lt;input type=\"radio\" class=\"form-check-input\" name=\"checkanswer[&lt;?php echo $row['ans_id']; ?>]\" value=\"&lt;?php echo $row['aid']; ?>\">\n                        &lt;?php echo $row['answer']; ?>\n                      &lt;\/div>\n                    &lt;?php endwhile ?>\n\n                  &lt;\/div>\n                &lt;\/div>\n              &lt;\/div>\n            &lt;?php endwhile ?>\n          &lt;?php endfor ?>\n\n            &lt;div class=\"col-md-8 mb-5\">\n              &lt;button type=\"submit\" class=\"btn btn-success\" name=\"answer-submit\">Submit Answers&lt;\/button>\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n    &lt;\/form>\n  &lt;\/section>\n\n  &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/js\/bootstrap.bundle.min.js\">&lt;\/script>\n&lt;\/body>\n&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n\n&lt;\/html><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/be-problem-solver\/image\/upload\/v1687167909\/quiz-dashboard_vvcuam.webp\" alt=\"Image of Dashboard of Online Quiz System Project in PHP\"\/><figcaption class=\"wp-element-caption\">Dashboard of Online Quiz System Project in PHP <\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Logic_Part_of_Online_Quiz_System\"><\/span>Logic Part of Online Quiz System<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a PHP script to process the submitted quiz form. Retrieve the selected answers from the form and compare them with the correct answers stored in the database. Calculate the user&#8217;s score based on the number of correct answers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>checkanswers.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"monokai\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;?php\nrequire_once(\"connect.php\");\nsession_start();\n\nif (isset($_POST['answer-submit'])) {\n\n  \/\/ Checking if our Questions are even attempted\n  if (!empty($_POST['checkanswer'])) {\n    \n    \/\/ Set a flag for correct answers\n    $correctAnswers = 0;\n    $selected = $_POST['checkanswer'];\n\n    $sql = \"SELECT * FROM questions\";\n    $result = mysqli_query($conn, $sql);\n\n    $i = 1;\n    while ($row = mysqli_fetch_assoc($result)) {\n      \/\/ Matching Database Answerid with User selected answer id\n      \/\/ If ans_id are matched our flag value is updated\n      if ($row['ans_id'] == $selected[$i]) {\n        $correctAnswers++;\n      }\n      $i++;\n    }\n\n    \/\/ Stored our score and attempted question value in session to be used on Result page\n    $_SESSION['attempted'] = count($_POST['checkanswer']);\n    $_SESSION['score'] = $correctAnswers;\n\n\n    header(\"Location: result.php\");\n    exit();\n\n  } else {\n    \/\/ If Question not attempted set these variable like this\n    $_SESSION['attempted'] = 0;\n    $_SESSION['score'] = 0;\n    header(\"Location: result.php\");\n    exit();\n  }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, to display the result, we code our <strong>result.php<\/strong> page for the online quiz system PHP source code. You can also show the correct answers for each question if desired.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/be-problem-solver\/image\/upload\/v1687168862\/result-page_f3cy5z.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Result Page of Online quiz system project in PHP <\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>result.php<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"monokai\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;?php\nrequire_once(\"connect.php\");\nrequire_once(\"function.php\");\nsession_start();\n\nif (!isset($_SESSION['login_active'])) {\n  header(\"Location: index.php\");\n  exit();\n}\n?>\n\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;title>Quiz&lt;\/title>\n  &lt;link href=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/css\/bootstrap.min.css\" rel=\"stylesheet\">\n  &lt;link rel=\"stylesheet\" href=\"css\/style.css\">\n&lt;\/head>\n\n&lt;body>\n  &lt;section class=\"main-section\">\n\n    &lt;nav class=\"navbar navbar-expand-lg bg-body-tertiary bg-dark\" data-bs-theme=\"dark\">\n      &lt;div class=\"container-fluid\">\n        &lt;a class=\"navbar-brand\" href=\"dashboard.php\">Quiz&lt;\/a>\n        &lt;button class=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarSupportedContent\">\n          &lt;span class=\"navbar-toggler-icon\">&lt;\/span>\n        &lt;\/button>\n        &lt;div class=\"collapse navbar-collapse\" id=\"navbarSupportedContent\">\n          &lt;ul class=\"navbar-nav me-auto mb-2 mb-lg-0\">\n            &lt;li class=\"nav-item\">\n              &lt;a class=\"nav-link active\" aria-current=\"page\" href=\"dashboard.php\">Dashboard&lt;\/a>\n            &lt;\/li>\n          &lt;\/ul>\n\n          &lt;div class=\"d-flex\">\n            &lt;a class=\"btn btn-danger\" href=\"logout.php\">Logout&lt;\/a>\n          &lt;\/div>\n        &lt;\/div>\n      &lt;\/div>\n    &lt;\/nav>\n\n    &lt;div class=\"container\">\n      &lt;div class=\"row justify-content-center\">\n        &lt;div class=\"col-md-8\">\n          &lt;?php if ($_SESSION['score'] == 0) : ?>\n            &lt;div class=\"card my-2 p-3 text-center\">\n              &lt;div class=\"card-body\">\n                &lt;h5 class=\"card-title py-2 text-center\">No Question Attempted&lt;\/h5>\n                &lt;button class=\"btn btn-warning\">You Score is : &lt;?php echo $_SESSION['score']; ?>&lt;\/button>\n              &lt;\/div>\n            &lt;\/div>\n\n          &lt;?php else : ?>\n            &lt;div class=\"card my-2 p-3 text-center\">\n              &lt;div class=\"card-body\">\n                &lt;h5 class=\"card-title py-2 text-center\">You have attempted &lt;?php echo $_SESSION['attempted']; ?> out of &lt;?php echo totalquestion($conn); ?>&lt;\/h5>\n                &lt;button class=\"btn btn-warning\">You Score: &lt;?php echo $_SESSION['score']; ?>&lt;\/button>&lt;span class=\"badge text-bg-primary\">Answered &lt;?php echo $_SESSION['score']; ?> Questions Successfully!&lt;\/span>\n              &lt;\/div>\n            &lt;\/div>\n\n          &lt;?php endif ?>\n\n          &lt;div class=\"card my-2 p-3 text-center\">\n            &lt;div class=\"card-body\">\n              &lt;a class=\"btn btn-info\" href=\"quiz.php\">Reattempt Quiz&lt;\/a>\n            &lt;\/div>\n          &lt;\/div>\n        &lt;\/div>\n\n      &lt;\/div>\n    &lt;\/div>\n    &lt;\/form>\n  &lt;\/section>\n\n  &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/js\/bootstrap.bundle.min.js\">&lt;\/script>\n&lt;\/body>\n\n&lt;!-- Coded by https:\/\/beproblemsolver.com  Visit for more such code -->\n&lt;\/html><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Download the full PHP multiple choice quiz source code from our GitHub link:<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/github.com\/PawanKumar-Dev\/simple-quiz-system-php-and-mysql\" target=\"_blank\" rel=\"noreferrer noopener\">Download Online Quiz System in PHP<\/a><\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In conclusion, the Online Quiz System Project in PHP is a powerful tool for conducting quizzes online. It allows users to register, take quizzes and see their scores easily. With its simple and intuitive interface, PHP multiple choice Quiz Source code also makes it fun for PHP developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you only want a PHP User Login system, check out <a href=\"https:\/\/beproblemsolver.com\/user-login-in-php-with-session\/\" data-type=\"URL\" data-id=\"https:\/\/beproblemsolver.com\/user-login-in-php-with-session\/\" target=\"_blank\" rel=\"noreferrer noopener\">this post<\/a>. With its user-friendly interface and a whole bunch of <a href=\"https:\/\/beproblemsolver.com\/best-visual-studio-code-extensions\/\" data-type=\"URL\" data-id=\"https:\/\/beproblemsolver.com\/best-visual-studio-code-extensions\/\" target=\"_blank\" rel=\"noreferrer noopener\">extensions<\/a>, you can download VS Code for your code projects too. Hope you liked it. Feel free to comment and share this article with friends and family.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also if you have any doubts or improvements, do share them with us. Ta-da! Keep Coding guys and gals!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uncover the source code &#038; step-by-step instructions to create a dynamic online quiz system in PHP to engage your audience.<\/p>\n","protected":false},"author":1,"featured_media":6263,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAow6-e6DA:productID":"","footnotes":""},"categories":[14,16,15],"tags":[8,71,12,11,7,6],"class_list":["post-4939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","category-mysql","category-php","tag-bootstrap-5","tag-css","tag-css3","tag-html5","tag-mysql","tag-php"],"_links":{"self":[{"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/posts\/4939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/comments?post=4939"}],"version-history":[{"count":0,"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/posts\/4939\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/media\/6263"}],"wp:attachment":[{"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/media?parent=4939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/categories?post=4939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beproblemsolver.com\/wp-json\/wp\/v2\/tags?post=4939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}