SlideShare una empresa de Scribd logo
1 de 5
Descargar para leer sin conexión
Php code for Online Quiz
                                                                                                       Quiz.php
<? include("db_mysql_connect.php"); ?>
<div id="heading">Online Quiz</div>
  <br />
  <form name="quiz" method="post" action="quiz.php">
    <? if($_POST["do"]=="finish")
                {
                $rans=$_POST["rans"];
                $tq=$_POST["tq"];
                $end=$_POST["end"];
                $startposition=$_POST["startposition"];
                echo "<table cellpadding='5px' align='center' style='border:1px solid silver' width='80%'
bgcolor='green'>";
                echo "<tr><td>Total Question Attempt</td><td>",$tq,"</td><tr>";
                echo "<tr><td>Correct Answer</td><td>",$rans,"</td></tr>";
                echo "<tr><td>Wrong Answer</td><td>",$tq-$rans,"</td></tr>";
                echo "<tr><td>Correct Answer Percentage</td><td>",$rans/$tq*100,"%</td></tr>";
                echo "<tr><td>Wrong Answer Percenntage</td><td>",($tq-$rans)/$tq*100,"%</td></tr>";
                echo "</table><br><br>";


                   $query="select * from quiz where qid<='$end' and qid>='$startposition'";

                                                  echo "<table cellpadding='5px' align='center' style='border:1px
solid silver'>";
                                                  echo "<tr><th colspan='4' id='heading'>Online Quiz Test
Question</td></tr>";
              $result=mysql_query($query);
              while ($row = mysql_fetch_array($result)) {
                echo "<tr><td>",$row[0],"</td><td colspan='2'>",$row[1],"</td></tr><tr><td></td>";
                                                         echo "<td colspan='2'>A. ",$row[2],"</td>";
                                                         echo "<td colspan='2'>B. ",$row[3],"</td></tr>";
                                                         echo "<tr><td></td><td colspan='2'>C. ",$row[4],"</td>";
                                                         echo "<td colspan='1'>D. ",$row[5],"</td></tr>";
                                                         echo "<tr><td colspan='4' align='right'
style='color:orange'>Correct option is ",strtoupper($row[6]),"</td></tr>";
                                                         echo "<tr><td colspan='4' align='right'
style='color:orange'><hr></td></tr>";


                   }
                   echo "</table>";
                   echo "<p align='right'><a href='#' onclick='window.print()'>Print</a></p>";
                   echo "<div style='visibility:hidden;display:none'>";

                   }


         “Online Quiz” Php Code By Gunjan Kumar                                                                     Page 1
?>
   <table cellpadding="5px" width="100%" style="border:1px solid silver">
    <?

                $start=$_POST["start"];
                $s=$_POST["startposition"];
                if($start==NULL)
                {
                $start=$_GET["start"];
                $s=$_GET["start"];
                }
                $useropt=$_POST["useropt"];
                $qid=$_POST["qid"];
                $rans=$_POST["rans"];
                $name=$_POST["name"];
                $totalquestion=$_POST["totalquestion"];
                if($start==NULL)
                $query="select * from quiz where qid='1'";
                else
                {
                $query="select * from quiz where qid='$start'";
                }
             $result=mysql_query($query);
             while ($row = mysql_fetch_array($result)) {
               echo "<tr><td>",$row[0],"</td><td colspan='2'>",$row[1],"</td></tr><tr><td></td><td
colspan='2'><input type='radio' name='useropt' value='a' /> ",$row[2],"</td><td colspan='2'><input type='radio'
name='useropt' value='b' /> ",$row[3],"</td></tr><tr><td></td><td colspan='2'><input type='radio'
name='useropt' value='c' /> ",$row[4],"</td><td colspan='2'><input type='radio' name='useropt' value='d' />
",$row[5],"</td></tr>";
                                                        echo "<tr ><td colspan='5' align='right'><input
type='hidden' name='name' value='",$name,"'><input type='hidden' name='start' value='",$row[0]+1,"'><input
type='hidden' name='qid' value='",$row[0],"'><input type='hidden' name='startposition' value='",$s,"'><input
type='submit' value='Next Question'><input type='hidden' name='totalquestion' value='",$totalquestion+1,"'>";

                 echo "</td></tr>";
             }
                                                echo "<tr><td colspan='4'>";
                                                $query="select woptcode from quiz where qid='$qid'";
                 $result=mysql_query($query);
                 while ($row = mysql_fetch_array($result)) {
                 if(strcmp($row[0],$useropt)==0)
                 {
                 echo "<input type='hidden' name='rans' value='",$rans+1,"'>";
                 $rans=$rans+1;
                 }
                 else
                 echo "<input type='hidden' name='rans' value='",$rans,"'>";
                 }

                 echo "</td></tr>";
                                                ?>
        “Online Quiz” Php Code By Gunjan Kumar                                                                Page 2
</table>
   <center>
   <br />
   <br />
  </form>
  <form method="post" action="quiz.php">
   <input type="hidden" name="do" value="finish" />
   <input type="hidden" name="rans" value="<? echo $rans;?>" />
   <input type="hidden" name="name" value="<? echo $name;?>" />
   <input type="hidden" name="tq" value="<? echo $totalquestion;?>" />
   <input type="hidden" name="end" value="<? echo $start-1;?>" />
   <input type="hidden" name="startposition" value="<? echo $s;?>" />
   <input type="submit" value="Finish Online Test" />
  </form>
                                       OUTPUT of Quiz.php




                                                   Fig-1




                                                   Fig-2
                                                                         Quiz_Entry_Admin.php
<? if($_POST["do"]=="quiz")
               {
                include("db_mysql_connect.php");
               $question=$_POST["question"];

       “Online Quiz” Php Code By Gunjan Kumar                                              Page 3
$opt1=$_POST["opt1"];
               $opt2=$_POST["opt2"];
               $opt3=$_POST["opt3"];
               $opt4=$_POST["opt4"];
               $woptcode=$_POST["woptcode"];
               $query="select * from quiz ";
               $temp=1;

            $result=mysql_query($query);
            while ($row = mysql_fetch_array($result)) {
                                                 $temp=$temp+1;
                                                 }
                                        $query="insert into quiz
values($temp,'$question','$opt1','$opt2','$opt3','$opt4','$woptcode')";
                                        $result=mysql_query($query);
                                        echo "successfully Saved";
               }
               ?>
               <form method="post" action="czone-stu-admin-login.php">
               <table>
               <tr><td colspan="2" id="heading">Online Quiz Test Question Entry Module</td>
               </tr>
               <tr>
               <td>Enter Question here </td>
               <td><input type="text" name="question" id="gunjan-textbox"/></td>
               </tr>
               <tr>
               <td>Enter First option</td>
               <td><input type="text" name="opt1" id="gunjan-textbox" /></td>
               </tr>
               <tr>
               <td>Enter Second option</td>
               <td><input type="text" name="opt2" id="gunjan-textbox" /></td>
               </tr>
               <tr>
               <td>Enter Third option</td>
               <td><input type="text" name="opt3" id="gunjan-textbox" /></td>
               </tr>
               <tr>
               <td>Enter Fourth option</td>
               <td><input type="text" name="opt4" id="gunjan-textbox" /></td>
               </tr>
               <tr>
               <td>Select Right Option code</td>
               <td><select name="woptcode" id="gunjan-textbox">
               <option value="a">A</option>
               <option value="b">B</option>
               <option value="c">C</option>
               <option value="d">D</option>
               </select>
               </td>
       “Online Quiz” Php Code By Gunjan Kumar                                                 Page 4
</tr>
               <tr>
               <td colspan="2">
               <input type="hidden" name="do" value="quiz" /><input type="submit" value="SAVE QUESTION" />
               </td>
               </tr>
               </table>
               </form>
                              OUTPUT of Quiz_Entry_Admin.php




                                                   Fig-3
                                                                             db_mysql_connect.php
<?
mysql_connect("localhost");
mysql_select_db("quiz") or die("database could not connect ");
?>
                                                                                      Mysql Table “Quiz”
CREATE TABLE `quiz` (
  `qid` int(5) default NULL,
  `Question` text,
  `opt1` text,
  `opt2` text,
  `opt3` text,
  `opt4` text,
  `woptcode` varchar(5) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

                           “Online Quiz” Php code is made for Distribution purpose;
                                     Modify it as per your requirement.
                                                   Thanks
                                               Gunjan Kumar
                                      gunjankumarverma@gmail.com
                                          Mobile - +91 9334457195



        “Online Quiz” Php Code By Gunjan Kumar                                                         Page 5

Más contenido relacionado

La actualidad más candente

PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks Damien Seguy
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegamehozayfa999
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An AnalysisJustin Finkelstein
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internalsjeresig
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome TownRoss Tuck
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland
 
Mongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is BrightMongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is Brightaaronheckmann
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationguest5d87aa6
 
The Ring programming language version 1.3 book - Part 33 of 88
The Ring programming language version 1.3 book - Part 33 of 88The Ring programming language version 1.3 book - Part 33 of 88
The Ring programming language version 1.3 book - Part 33 of 88Mahmoud Samir Fayed
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentationguestcf600a
 

La actualidad más candente (15)

Knockout
KnockoutKnockout
Knockout
 
PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegame
 
PHP Tutorial (funtion)
PHP Tutorial (funtion)PHP Tutorial (funtion)
PHP Tutorial (funtion)
 
Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An Analysis
 
Groovy kind of test
Groovy kind of testGroovy kind of test
Groovy kind of test
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internals
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
Tt subtemplates-caching
Tt subtemplates-cachingTt subtemplates-caching
Tt subtemplates-caching
 
Mongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is BrightMongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is Bright
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
The Ring programming language version 1.3 book - Part 33 of 88
The Ring programming language version 1.3 book - Part 33 of 88The Ring programming language version 1.3 book - Part 33 of 88
The Ring programming language version 1.3 book - Part 33 of 88
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 

Similar a Php code for online quiz

C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample PhpJH Lee
 
Php update and delet operation
Php update and delet operationPhp update and delet operation
Php update and delet operationsyeda zoya mehdi
 
R57shell
R57shellR57shell
R57shellady36
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Let's write secure drupal code!
Let's write secure drupal code!Let's write secure drupal code!
Let's write secure drupal code!Balázs Tatár
 
Why Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary ThingWhy Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary ThingChris Reynolds
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介純生 野田
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in actionJace Ju
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console componentHugo Hamon
 
Java.script
Java.scriptJava.script
Java.scriptg Nama
 

Similar a Php code for online quiz (20)

C A S Sample Php
C A S Sample PhpC A S Sample Php
C A S Sample Php
 
Update statement in PHP
Update statement in PHPUpdate statement in PHP
Update statement in PHP
 
Php update and delet operation
Php update and delet operationPhp update and delet operation
Php update and delet operation
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 
R57shell
R57shellR57shell
R57shell
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Php (1)
Php (1)Php (1)
Php (1)
 
Daily notes
Daily notesDaily notes
Daily notes
 
Let's write secure drupal code!
Let's write secure drupal code!Let's write secure drupal code!
Let's write secure drupal code!
 
Why Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary ThingWhy Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary Thing
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Coding part
Coding partCoding part
Coding part
 
Php functions
Php functionsPhp functions
Php functions
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介
 
PowerCMS X
PowerCMS XPowerCMS X
PowerCMS X
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Java.script
Java.scriptJava.script
Java.script
 

Último

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Último (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Php code for online quiz

  • 1. Php code for Online Quiz Quiz.php <? include("db_mysql_connect.php"); ?> <div id="heading">Online Quiz</div> <br /> <form name="quiz" method="post" action="quiz.php"> <? if($_POST["do"]=="finish") { $rans=$_POST["rans"]; $tq=$_POST["tq"]; $end=$_POST["end"]; $startposition=$_POST["startposition"]; echo "<table cellpadding='5px' align='center' style='border:1px solid silver' width='80%' bgcolor='green'>"; echo "<tr><td>Total Question Attempt</td><td>",$tq,"</td><tr>"; echo "<tr><td>Correct Answer</td><td>",$rans,"</td></tr>"; echo "<tr><td>Wrong Answer</td><td>",$tq-$rans,"</td></tr>"; echo "<tr><td>Correct Answer Percentage</td><td>",$rans/$tq*100,"%</td></tr>"; echo "<tr><td>Wrong Answer Percenntage</td><td>",($tq-$rans)/$tq*100,"%</td></tr>"; echo "</table><br><br>"; $query="select * from quiz where qid<='$end' and qid>='$startposition'"; echo "<table cellpadding='5px' align='center' style='border:1px solid silver'>"; echo "<tr><th colspan='4' id='heading'>Online Quiz Test Question</td></tr>"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<tr><td>",$row[0],"</td><td colspan='2'>",$row[1],"</td></tr><tr><td></td>"; echo "<td colspan='2'>A. ",$row[2],"</td>"; echo "<td colspan='2'>B. ",$row[3],"</td></tr>"; echo "<tr><td></td><td colspan='2'>C. ",$row[4],"</td>"; echo "<td colspan='1'>D. ",$row[5],"</td></tr>"; echo "<tr><td colspan='4' align='right' style='color:orange'>Correct option is ",strtoupper($row[6]),"</td></tr>"; echo "<tr><td colspan='4' align='right' style='color:orange'><hr></td></tr>"; } echo "</table>"; echo "<p align='right'><a href='#' onclick='window.print()'>Print</a></p>"; echo "<div style='visibility:hidden;display:none'>"; } “Online Quiz” Php Code By Gunjan Kumar Page 1
  • 2. ?> <table cellpadding="5px" width="100%" style="border:1px solid silver"> <? $start=$_POST["start"]; $s=$_POST["startposition"]; if($start==NULL) { $start=$_GET["start"]; $s=$_GET["start"]; } $useropt=$_POST["useropt"]; $qid=$_POST["qid"]; $rans=$_POST["rans"]; $name=$_POST["name"]; $totalquestion=$_POST["totalquestion"]; if($start==NULL) $query="select * from quiz where qid='1'"; else { $query="select * from quiz where qid='$start'"; } $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "<tr><td>",$row[0],"</td><td colspan='2'>",$row[1],"</td></tr><tr><td></td><td colspan='2'><input type='radio' name='useropt' value='a' /> ",$row[2],"</td><td colspan='2'><input type='radio' name='useropt' value='b' /> ",$row[3],"</td></tr><tr><td></td><td colspan='2'><input type='radio' name='useropt' value='c' /> ",$row[4],"</td><td colspan='2'><input type='radio' name='useropt' value='d' /> ",$row[5],"</td></tr>"; echo "<tr ><td colspan='5' align='right'><input type='hidden' name='name' value='",$name,"'><input type='hidden' name='start' value='",$row[0]+1,"'><input type='hidden' name='qid' value='",$row[0],"'><input type='hidden' name='startposition' value='",$s,"'><input type='submit' value='Next Question'><input type='hidden' name='totalquestion' value='",$totalquestion+1,"'>"; echo "</td></tr>"; } echo "<tr><td colspan='4'>"; $query="select woptcode from quiz where qid='$qid'"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { if(strcmp($row[0],$useropt)==0) { echo "<input type='hidden' name='rans' value='",$rans+1,"'>"; $rans=$rans+1; } else echo "<input type='hidden' name='rans' value='",$rans,"'>"; } echo "</td></tr>"; ?> “Online Quiz” Php Code By Gunjan Kumar Page 2
  • 3. </table> <center> <br /> <br /> </form> <form method="post" action="quiz.php"> <input type="hidden" name="do" value="finish" /> <input type="hidden" name="rans" value="<? echo $rans;?>" /> <input type="hidden" name="name" value="<? echo $name;?>" /> <input type="hidden" name="tq" value="<? echo $totalquestion;?>" /> <input type="hidden" name="end" value="<? echo $start-1;?>" /> <input type="hidden" name="startposition" value="<? echo $s;?>" /> <input type="submit" value="Finish Online Test" /> </form> OUTPUT of Quiz.php Fig-1 Fig-2 Quiz_Entry_Admin.php <? if($_POST["do"]=="quiz") { include("db_mysql_connect.php"); $question=$_POST["question"]; “Online Quiz” Php Code By Gunjan Kumar Page 3
  • 4. $opt1=$_POST["opt1"]; $opt2=$_POST["opt2"]; $opt3=$_POST["opt3"]; $opt4=$_POST["opt4"]; $woptcode=$_POST["woptcode"]; $query="select * from quiz "; $temp=1; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { $temp=$temp+1; } $query="insert into quiz values($temp,'$question','$opt1','$opt2','$opt3','$opt4','$woptcode')"; $result=mysql_query($query); echo "successfully Saved"; } ?> <form method="post" action="czone-stu-admin-login.php"> <table> <tr><td colspan="2" id="heading">Online Quiz Test Question Entry Module</td> </tr> <tr> <td>Enter Question here </td> <td><input type="text" name="question" id="gunjan-textbox"/></td> </tr> <tr> <td>Enter First option</td> <td><input type="text" name="opt1" id="gunjan-textbox" /></td> </tr> <tr> <td>Enter Second option</td> <td><input type="text" name="opt2" id="gunjan-textbox" /></td> </tr> <tr> <td>Enter Third option</td> <td><input type="text" name="opt3" id="gunjan-textbox" /></td> </tr> <tr> <td>Enter Fourth option</td> <td><input type="text" name="opt4" id="gunjan-textbox" /></td> </tr> <tr> <td>Select Right Option code</td> <td><select name="woptcode" id="gunjan-textbox"> <option value="a">A</option> <option value="b">B</option> <option value="c">C</option> <option value="d">D</option> </select> </td> “Online Quiz” Php Code By Gunjan Kumar Page 4
  • 5. </tr> <tr> <td colspan="2"> <input type="hidden" name="do" value="quiz" /><input type="submit" value="SAVE QUESTION" /> </td> </tr> </table> </form> OUTPUT of Quiz_Entry_Admin.php Fig-3 db_mysql_connect.php <? mysql_connect("localhost"); mysql_select_db("quiz") or die("database could not connect "); ?> Mysql Table “Quiz” CREATE TABLE `quiz` ( `qid` int(5) default NULL, `Question` text, `opt1` text, `opt2` text, `opt3` text, `opt4` text, `woptcode` varchar(5) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; “Online Quiz” Php code is made for Distribution purpose; Modify it as per your requirement. Thanks Gunjan Kumar gunjankumarverma@gmail.com Mobile - +91 9334457195 “Online Quiz” Php Code By Gunjan Kumar Page 5