php mcq – html code for online quiz program

php mcq : online quiz project in php and mysql, php quiz code, php mysql multiple choice quiz source code and php coding test questions.

php mcq – php coding test questions

Source Code of Online Quiz in PHP : Our 10+ PHP Programming MCQ (Multiple Choice Questions and Answers) focus on all areas of PHP Programming covering 5+ topics.

Here, i will create a web-based application(php mcq) for php mysql multiple choice quiz source code.

For making the php quiz code application, i needed to develop the following all the files;

  1. database_connection.php
  2. index.php
  3. retrievemcqTest.php
  4. retrivesolutions.php
  5. saveallmcq.php

PHP MCQ Questions : This section focuses on “Basics” of PHP.

php mysql multiple choice quiz source code

database_connection.php
This PHP file source contains all code about database_connection.php.


Don’t Miss : php mysql multiple choice quiz source code

index.php
This main file data contains all source code about main root file index.php.





Quiz Application - online quiz project in php and mysql


MCQs Application - www.pakainfo.com

Enter your name:      

retrievemcqTest.php
This PHP file data contains all code about get a allthe the mcqTest data.

';
echo '
'; echo ''; // get mcq McqQues and their options $sqlMCQs = "SELECT * FROM questions_master"; $solutionMCQs = mysqli_query($con, $sqlMCQs); while ($rowMCQs = mysqli_fetch_assoc($solutionMCQs)){ $id = $rowMCQs['id']; $question = $rowMCQs['question']; $selection1 = $rowMCQs['op1']; $selection2 = $rowMCQs['op2']; $selection3 = $rowMCQs['op3']; $answer = $rowMCQs['answer']; echo '
'; echo '

Question #'.$no.'


'; echo '

'.$question.'


'; echo '

Options


'; echo ''.$selection1.'    '; echo ''.$selection2.'    '; echo ''.$selection3.'    '; echo '
'; $no++; } echo '
'; echo '
'; echo '
'; } }

retrivesolutions.php
This data file contains all source code about get the all solutions.

Enter your name and click Take mcqTest button!


'; echo ''; $sqlScore = "select * from member"; $solutionScore = mysqli_query($con, $sqlScore); while ($rowScore = mysqli_fetch_assoc($solutionScore)){ $name = $rowScore['name']; $score = $rowScore['score']; echo ''; $no++; } echo '
#NameScore
'.$no.''.$name.''.$score.'
'; echo '
'; }

saveallmcq.php
This php file data contains all the source code about submitting or save the quiz.

 $value) {
if($key == 'nameofmember'){
}else if ($key == 'submit') {
}
else{
$tempAnswer = $_POST[$key];
// count total McqQues and correct answers
$sqlAnswer = "select  count(*) count from questions_master where id = '$key' and answer = '$tempAnswer'";
$solutionAnswer = mysqli_query($con, $sqlAnswer);
$rowAnswer = mysqli_fetch_assoc($solutionAnswer);
$numAnswer = $rowAnswer['count'];
if ($numAnswer < 1){
// wrong answer
}
else {
// correct answer
$correctAnswers++;
}
$totalMcqQues++;
}  
}
// Store score in db
$sqlSubmit = "insert into member (name, score) values ('$nameofmember', '$correctAnswers/$totalMcqQues')";
if (mysqli_query($con, $sqlSubmit)){
header("Location: index.php?status=succes");
} else {
header("Location: index.php?status=error");
}
}

I hope you get an idea about php quiz code - how to create quiz in php and mysql?.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment