Build a Simple Quiz In PHP: This is so easy to make. But, when you have knowledge in PHP. This Quiz was created with PHP, HTML & CSS, Easy to create and you can use it anywhere. This programme is basically based on PHP but, you don’t have to create a database for it. I had created with the help of method=”post” & var $ ( PHP variables ) only.
You May Like Previously Shared Posts
Login System in PHP and MySQL | Complete Registration System
Free Bootstrap Login Form Source Code
PHP Quiz Code
I had created a very simple quiz program and now I am sharing this Quiz Code. As always, I am sharing a clean, basic & simple code. I think this is the strength of this blog. This is very simple So, easy to understand. This programs have many issues I have already said this is basic for better learning and understanding. Here is a preview of this below:
Source Code Below Here:
There are 3 files, “quiz.php” “result.php” & “style.css”. You have to create 3 files named here given.
First, create a file named “quiz.php“. in this file you have to make a quiz template with question & answers form. In <head> </head> section you have to link CSS file name “style.css” & Put “result.php” in submit action.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
<!DOCTYPE html> <!--code by webdevtrick (webdevtrick.com) --> <head> <meta charset=UTF-8" /> <title>PHP QUIZ | Webdevtrick.com</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="page-wrap"> <h1>Simple Quiz Built On PHP</h1> <form action="result.php" method="post" id="quiz"> <ol> <li> <h3>WordPress is a...</h3> <div> <input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" /> <label for="question-1-answers-A">A) Software </label> </div> <div> <input type="radio" name="question-1-answers" id="question-1-answers-B" value="B" /> <label for="question-1-answers-B">B) Web App</label> </div> <div> <input type="radio" name="question-1-answers" id="question-1-answers-C" value="C" /> <label for="question-1-answers-C">C) CMS</label> </div> <div> <input type="radio" name="question-1-answers" id="question-1-answers-D" value="D" /> <label for="question-1-answers-D">D) Other</label> </div> </li> <li> <h3>SEO is Part Of...</h3> <div> <input type="radio" name="question-2-answers" id="question-2-answers-A" value="A" /> <label for="question-2-answers-A">A) Video Editing</label> </div> <div> <input type="radio" name="question-2-answers" id="question-2-answers-B" value="B" /> <label for="question-2-answers-B">B) Graphic Designing</label> </div> <div> <input type="radio" name="question-2-answers" id="question-2-answers-C" value="C" /> <label for="question-2-answers-C">C) Web Designing</label> </div> <div> <input type="radio" name="question-2-answers" id="question-2-answers-D" value="D" /> <label for="question-2-answers-D">D) Digital Marketing</label> </div> </li> <li> <h3>PHP is a....</h3> <div> <input type="radio" name="question-3-answers" id="question-3-answers-A" value="A" /> <label for="question-3-answers-A">A) Server Side Script</label> </div> <div> <input type="radio" name="question-3-answers" id="question-3-answers-B" value="B" /> <label for="question-3-answers-B">B) Programming Language</label> </div> <div> <input type="radio" name="question-3-answers" id="question-3-answers-C" value="C" /> <label for="question-3-answers-C">C) Markup Language</label> </div> <div> <input type="radio" name="question-3-answers" id="question-3-answers-D" value="D" /> <label for="question-3-answers-D">D) None Of Above These</label> </div> </li> <li> <h3>Localhost IP is..</h3> <div> <input type="radio" name="question-4-answers" id="question-4-answers-A" value="A" /> <label for="question-4-answers-A">A) 192.168.0.1</label> </div> <div> <input type="radio" name="question-4-answers" id="question-4-answers-B" value="B" /> <label for="question-4-answers-B">B) 127.0.0.0</label> </div> <div> <input type="radio" name="question-4-answers" id="question-4-answers-C" value="C" /> <label for="question-4-answers-C">C) 1080:80</label> </div> <div> <input type="radio" name="question-4-answers" id="question-4-answers-D" value="D" /> <label for="question-4-answers-D">D) Any Other</label> </div> </li> <li> <h3>Webdevtrick Is For</h3> <div> <input type="radio" name="question-5-answers" id="question-5-answers-A" value="A" /> <label for="question-5-answers-A">A) Web Designer</label> </div> <div> <input type="radio" name="question-5-answers" id="question-5-answers-B" value="B" /> <label for="question-5-answers-B">B) Web Developer</label> </div> <div> <input type="radio" name="question-5-answers" id="question-5-answers-C" value="C" /> <label for="question-5-answers-C">C) Graphic Designer</label> </div> <div> <input type="radio" name="question-5-answers" id="question-5-answers-D" value="D" /> <label for="question-5-answers-D">D) All Above These</label> </div> </li> </ol> <input type="submit" value="Submit" class="submitbtn" /> </form> </div> </body> </html> |
Now you have to create a file named “result.php” and paste codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<!DOCTYPE html> <!--code by webdevtrick (webdevtrick.com) --> <html> <head> <meta charset=UTF-8" /> <title>PHP Quiz</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="page-wrap"> <h1>Result | Webdevtrick.com</h1> <?php $answer1 = $_POST['question-1-answers']; $answer2 = $_POST['question-2-answers']; $answer3 = $_POST['question-3-answers']; $answer4 = $_POST['question-4-answers']; $answer5 = $_POST['question-5-answers']; $totalCorrect = 0; if ($answer1 == "C") { $totalCorrect++; } if ($answer2 == "D") { $totalCorrect++; } if ($answer3 == "A") { $totalCorrect++; } if ($answer4 == "B") { $totalCorrect++; } if ($answer5 == "D") { $totalCorrect++; } echo "<div id='results'>$totalCorrect / 5 correct</div>"; ?> </div> </body> </html> |
Finally, You have to give this quiz form some style, In other words, decoration. Create a file named “style.css”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/* Code By Webdevtrick (https://webdevtrick.com) */ body{ font: 14px Georgia, serif; } #page-wrap { width: 500px; margin: 0 auto;} h1 { margin: 25px 0; font: 18px Georgia, Serif; text-transform: uppercase; letter-spacing: 3px; } #quiz input { vertical-align: middle; } #quiz ol { margin: 0 0 10px 20px; } #quiz ol li { margin: 0 0 20px 0; } #quiz ol li div { padding: 4px 0; } #quiz h3 { font-size: 17px; margin: 0 0 1px 0; color: #666; } #results { font: 44px Georgia, Serif; } |
That’s It, Now you’re done. You have successfully created a simple quiz program. Note: PHP always runs on a server. So, you have to run this program in hosting or localhost. I hope this article will be helpful or useful to you. For Localhost, Download Xampp. If you have any question or suggestion comment down below.
Thanks For Visiting, Keep Visiting.
As a PHP newbie this was a lot of help thanks. I needed to create fun little quizzes for a comedy website and this is the perfect solution because it’s so simple! It worked nicely 🙂
I have an error
Undefined index:question-1-answers This error is repeat for each 4 questions
Hi Shaan,
Can we speak over a call?
Revert to my message via email. I am working on a project related to quizzes. Need a little help.
Thanks and regards
I am seeking home based php job(part time).I have experience in Php,Javascript,Ajax,Codeigniter.
So,If any jobwork exists, Please Contact me in this email:
sourav1001@gmail.com
Thank you so much for your help. This is really simple and easy to incorporate.
Thanks.pls want d questions one per page.want also total for each of d 4 subjects before grand total.
Thank you so much for your help. This is really simple and easy to incorporate.
this code is use full thank you for sharing this code
I am going to use this code in my project thanks.
is there anyone please who can help me to export this php quiz data result after submitting to excel or pdf or even on simple txt page will be fine ?
please send me code for this i will be thankful for your support.
thank you very much it’s very useful and simple code
nice
how to put in database?
thanks a lot that help , any code code that cans end the result to the admin email instead on screen