PHP - Php Online Quiz Application
Hello php gurus,...i need some help here for my php online quiz application.
I am doing an online quiz application,where at first a tutor will enter the question and selection of answers,and following by the correct answer through a form. Code: [Select] <html> <body> <form action="insert.php" method="post"> <p>Question: <input type="text" name="Q" /> </p ><p>Answer1: <input type="text" name="A" /> </p> <p>Answer2: <input type="text" name="B" /> </p> <p>Correct Answer: <input type="text" name="ans" /> </p> <p> <input type="submit" /> </p> </form> </body> </html> All the details will be sent to mysql database,and the database structure will be like this : Quote Question AnswerA AnswerB CorrectAnswer 1+1 2 4 A 2+3 6 5 B After that,i have created a php codes to retrieve the Questions from database,and display it in webpage,and the AnswerA and AnswerB will be shown in radio button.So users can choose the answer using radio button... My problem is,i don't know how to compare the 'value' in radio button with the 'CorrectAnswer' in the database,to know the correct answer. And also don't have idea how to calculate the correct answer and getting the results. So,if anyone could help me..i will be really gratefull... Hope can get the solution....plss help me Thank you very much I have attached my documents here... [attachment deleted by admin] Similar Tutorialsi want online quiz in php mysql So I'm trying to make an online quiz where the user can 'take the quiz' or go to 'module' where the user can edit the quiz. I've tried for days to search through the net for this particular one but I can't find any solutions. For the quiz I made a comma delimited text file and tried to use that file to make a multidimensional array. So far I only have the following: <h2>ONLINE QUIZ</h2> <ul> <li><a href='question.php'>Take quiz</a></li> <li><a href='module.php'>Admin Module</a></li> </ul> <?php $file = fopen ("data.txt","r"); $i=0; while (feof($file)==false) { $line = fgets($file); $array[$i]=$line; $i=$i + 1; } fclose($file); session_start(); $_SESSION["questions_array"]=$array; ?> My question is, how do I turn the text file from something that looks like this: HTML is...,Main markup language for web pages,Cross-site Security,Cleverly Structured Scripting,eXtremely Safe and Secure, PHP...,General-purpose server-side scripting language,Cross-site Security,Processing Hypertext Products,Process HTML Prettily To output something like this: Question #1 HTML is... [radio button] a.) Main markup language for web pages [radio button] b.) Cross-site Security etc, etc ll----I will type out the exact plan for this quiz----ll Main page: module and quiz link. For the quiz Question page: Questions only show up one by one. ex.) What is a dog? a.) a human b.) a pet c.) a job d.) a car (Submit button) Answer page: Once submit is hit, the page goes here, where the user can see whether they answered right or wrong. ex.) INCORRECT Your answer: a.) a human Correct answer: b.) a pet (continue link) Note that when 'continue' is hit, the page redirects back to the 'question page' but this time outputs the next question. When no more questions are available, the page automatically redirects to the 'results page'. Results page: Table of results For the module Main: A table of the available questions plus their choice answers ex.) Question l choice a l choice b l [] What? cat toy [] How? rat pop etc. Each row can be selected through a radio button. (so we know which question to edit) Select option: Drop down list whether to 'add', 'edit' or 'delete' a question. Each choice directs to a different page where you can perform the action. Also, if 'delete' is chosen, a confirmation page should show up. (i.e are you sure you want to delete this file?) I think that's detailed enough, I'm so sorry for the trouble;; but please if you don't have the time to help me throughout the whole thing, please help me figure out how to use the text file as a multi-dim array (aka the first thing I asked). I've been dying to know how to do it but I just can't get it to work so I'd really appreciate that! Thank you! Hi, I need a small help. Here is my situation. I am using a MVC application (e.g. Joomla or Drupal) which has a .htaccess redirect rule that all requests are passed through index.php file. That's normal and this is my main application. Now I installed another application within the application folder structure. What I want do do here is to allow opening the third party application URLs after one logged into my main application. Can anybody provide me some pointers to do the same? Please let me know if you need any further information on this. Any solution irrespective of framework will work. Thanks! Anupam Hello. I try to write a simple multiple choice quiz. I have my questions and answers in a xml file and I read the file into an array. My main problems is how I'll connect the various sessions where the different questions appear in order to keep the score and sum it up in the end. Also, how do I check if the selected answer is correct or not? Assuming that the correct answers are in an array in php code, can I use javascript to check the answers? Any help? Thanks. can anyone please tell me how can I make a quiz in php which displays random questions one at a time
Hey guys,
I'm making php quiz, but got some problems with results getting - they are all wrong. Here is the db table for it.
CREATE TABLE IF NOT EXISTS `quiz` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `question` text COLLATE utf8_unicode_ci NOT NULL, `answer1` text COLLATE utf8_unicode_ci NOT NULL, `answer2` text COLLATE utf8_unicode_ci NOT NULL, `answer3` text COLLATE utf8_unicode_ci NOT NULL, `correctanswer` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `pollid` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=34 ;And script itself. $questionNumber = 1; $query = sql_query("SELECT * FROM quiz ORDER BY RAND() LIMIT $limit"); while ($result = mysqli_fetch_array($query)) { ?> <div class="padding"> <p> <?php echo "<b><h4>" . $questionNumber . ") " . $result['question'] . "</h4><br></b>"; ?> <input type="radio" name="answer[<?php echo $result['id'] ?>]" value=""> <?php echo $result['answer1']; ?> <br> <input type="radio" name="answer[<?php echo $result['id'] ?>]" value=""> <?php echo $result['answer2']; ?> <br> <input type="radio" name="answer[<?php echo $result['id'] ?>]" value=""> <?php echo $result['answer3']; ?> <br> </p> <hr> </div> <?php $questionNumber +=1; } $correctAnswers = 0; $wrongAnswers = 0; $questions = ''; $idList = join (',', array_map('intval', array_keys($_POST['answer']))); $sql = "SELECT id, question, answer1, answer2, answer3, correctanswer FROM quiz WHERE id IN ($idList)"; $res = sql_query($sql) ; $qno = 1; while (list($id, $q, $a, $b, $c, $correct) = mysqli_fetch_row($res)) { if ($correct == $_POST['answer'][$id]) { $correctAnswers +=1; } else { $wrongAnswers +=1; } } echo $correctAnswer; echo $wrongAnswers; ?>Help me guys! Hey all! I am new to these forums, but this seems like a really good place for information. I am a beginner in PHP coding, so I don't have that much experience with how to do quite simple tasks. I have a job to fulfill and I have to create a personality quiz, which basically means a user answers about eight questions with three choices and then he will be dubbed as one of six different personalities. I've tired doing this, believe me, but I just don't get it to work. Are there any websites, downloads, or words of advice you guys could give me? And no, I will not be using one of those quiz generators online; it should be made from raw code. Thank you so much! There are ten list or bookmarks from Prof. Horner's Bible-Reading System found (http://www.facebook.com/group.php?gid=46416541831) each having set number of books from the Bible. One is to read ten chapters a day, one chapter from each of the bookmarks. Type in what day you are on and the program will show you on each of the lists as to what chapter you are suppose to be on. Also want to show statistics that will display how many times the Bible has been read with a break down of all 66 books of the Bible. Started a git respo http://github.com/Kutakizukari/Prof-Horners-Bible-Reading-System Bookmark list as follows: //List 1 $Matthew = 28; $Mark = 16; $Luke = 24; $John = 21; //List 2 $Genesis = 50; $Exodus = 40; $Levitieus = 27; $Numbers = 36; $Deuteronomy = 34; //List 3 $Romans = 16; $I_Corinthians = 16; $II_Corinthians = 13; $Galatians = 6; $Ephesians = 6; $Philipians = 4; $Colossians = 4; $Hebrews = 13; //List 4 $I_Thessalonians = 5; $II_Thessalonians = 3; $I_Timothy = 6; $II_Timothy = 4; $Titus = 3; $Philemon = 1; $James = 5; $I_Peter = 5 ; $II_Peter = 3 ; $I_John = 5; $II_John = 1; $III_John = 1; $Jude = 1; $Revelation = 22; //List 5 $Job = 42; $Ecclesiastes = 12; $Songs_of_Solomon = 8; //List 6 $Psalms = 150; //List 7 $Proverbs = 31; //List 8 $Joshua = 24; $Judges = 21; $Ruth = 4; $I_Samuel = 31; $II_Samuel = 24; $I_Kings = 22; $II_Kings = 25; $I_Chronicles = 29; $II_Chronicles = 36; $Ezra = 10; $Nehemiah = 13; $Esther = 10; //List 9 $Isaiah = 66; $Jeremiah = 52; $Lamentations = 5; $Ezekiel = 48; $Daniel = 12; $Hosea = 14; $Joel = 3; $Amos = 9; $Obadiah = 1; $Jonah = 4; $Micah = 7; $Nahum = 3; $Habakkuk = 3; $Zephaniah = 3; $Haggai = 2; $Zechariah = 14; $Malachi = 4; so on day 1 it should readout Matthew Chapter 1 Genesis Chapter 1 Romans Chapter 1 I Thessalonians Chapter 1 Job Chapter 1 Psalms Chapter 1 Proverbs Chapter 1 Joshua Chapter 1 Isaiah Chapter 1 Acts Chapter 1 on the second day it should all say Chapter two but Matthew reaches day 28 it should move on to Mark Chapter 1 and so on and so on and with each bookmark list. Hi all, Can anyone offer assistance with the following: I am trying to obtain a score from a users radio button selection on a simple quiz. i am not able to obtain the results.... Hey, I want to start by saying this is the first time I've ever looked at PHP. I'm using a Wordpress plugin from http://www.netconcepts.com/wordpress-quiz-plugin/ The user answers a few questions, and based off that, they get a results sheet with their personality type. The only issue is that none of the line breaks that I've used in the results show up. It's just one big paragraph (even when in the editing stage, I've made it look all nice). There's no plugin support for this. I think it has something to do with this file maybe... "<?php /* Copyright (c) 2007 Andrew Shell (http://blog.andrewshell.org) and Netconcepts (http://www.netconcepts.com) WordPress Quiz Plugin is released under the GNU General Public License (GPL) http://www.gnu.org/licenses/gpl.txt */ class WQP_Factory { function add_quiz_type($type, $typename, $classname, $classpath) { if (!isset($GLOBALS['WQP_Factory']['QUIZ_TYPES']) || !is_array($GLOBALS['WQP_Factory']['QUIZ_TYPES'])) { $GLOBALS['WQP_Factory']['QUIZ_TYPES'] = array(); } $GLOBALS['WQP_Factory']['QUIZ_TYPES'][$type] = array( 'type' => $type, 'typename' => $typename, 'classname' => $classname, 'classpath' => $classpath ); } function get_quiz_types() { if (!isset($GLOBALS['WQP_Factory']['QUIZ_TYPES']) || !is_array($GLOBALS['WQP_Factory']['QUIZ_TYPES'])) { $GLOBALS['WQP_Factory']['QUIZ_TYPES'] = array(); } return $GLOBALS['WQP_Factory']['QUIZ_TYPES']; } function by_id($quiz_id) { require_once dirname(__FILE__) . "/wqp-quiz.php"; global $wpdb; $quiz_id = intval($quiz_id); $sql = "SELECT * FROM " . $wpdb->wqp_quizzes . " WHERE quiz_id = {$quiz_id} LIMIT 1"; $row = $wpdb->get_row($sql); $quiz_type = strtolower($row->quiz_type); $quiz_types = WQP_Factory::get_quiz_types(); if (empty($quiz_type)) { return null; } elseif (!isset($quiz_types[$quiz_type])) { die("Invalid Quiz Type: {$quiz_type}"); } $quiz_class = $quiz_types[$quiz_type]['classname']; $quiz_file = $quiz_types[$quiz_type]['classpath']; require_once $quiz_file; $quiz = new $quiz_class($row->quiz_id); $data = unserialize($row->quiz_data); $quiz->assign_all($data); return $quiz; } function by_type($quiz_type) { require_once dirname(__FILE__) . "/wqp-quiz.php"; $quiz_type = strtolower($quiz_type); $quiz_types = WQP_Factory::get_quiz_types(); if (!isset($quiz_types[$quiz_type])) { die("Invalid Quiz Type: {$quiz_type}"); } $quiz_class = $quiz_types[$quiz_type]['classname']; $quiz_file = $quiz_types[$quiz_type]['classpath']; require_once $quiz_file; $quiz = new $quiz_class(); $quiz->assign_defaults(); return $quiz; } } if (!function_exists('scandir')) { function scandir($directory, $sorting_order = 0) { if (!is_string($directory)) { user_error('scandir() expects parameter 1 to be string, ' . gettype($directory) . ' given', E_USER_WARNING); return; } if (!is_int($sorting_order) && !is_bool($sorting_order)) { user_error('scandir() expects parameter 2 to be long, ' . gettype($sorting_order) . ' given', E_USER_WARNING); return; } if (!is_dir($directory) || (false === $fh = @opendir($directory))) { user_error('scandir() failed to open dir: Invalid argument', E_USER_WARNING); return false; } $files = array (); while (false !== ($filename = readdir($fh))) { $files[] = $filename; } closedir($fh); if ($sorting_order == 1) { rsort($files); } else { sort($files); } return $files; } } // Escape output string function wqp_escape_string($value) { $escaped = $value; $escaped = wp_specialchars($escaped, true); return $escaped; } // Filter input string function wqp_filter_string($value) { $filtered = $value; $filtered = strip_tags($filtered); $filtered = stripslashes($filtered); return $filtered; } function wqp_safe_array(&$value, $default_value = array()) { if (!isset($default_value) || !is_array($default_value)) { $default_value = array(); } return (isset($value) && is_array($value) ? $value : $default_value); } function wqp_safe_value(&$value, $default_value = '') { return (isset($value) ? $value : $default_value); } function wqp_the_content($content) { preg_match_all( '!\[quiz=([0-9]+)\]!isU', $content, $matches ); foreach (array_keys($matches[0]) as $i) { $quiz = WQP_Factory::by_id($matches[1][$i]); if (!empty($quiz) && is_object($quiz)) { if (isset($_POST['answer']) && is_array($_POST['answer'])) { $content = str_replace($matches[0][$i], $quiz->fetch_answer($_POST['answer']), $content); } else { $content = str_replace($matches[0][$i], $quiz->fetch_quiz(), $content); } } } return $content; } function wqp_the_title($title) { preg_match_all( '!\[quiz=([0-9]+)\]!isU', $title, $matches ); foreach (array_keys($matches[0]) as $i) { $quiz = WQP_Factory::by_id($matches[1][$i]); if (!empty($quiz) && is_object($quiz)) { $title = str_replace($matches[0][$i], $quiz->get_title(), $title); } } return $title; } function wqp_get_query_template($template_dir, $type) { $template = ''; if (file_exists(TEMPLATEPATH . "/{$type}.php")) { $template = TEMPLATEPATH . "/{$type}.php"; } elseif (file_exists($template_dir . "/{$type}.php")) { $template = $template_dir . "/{$type}.php"; } return apply_filters("wqp_{$type}_template", $template); } function wqp_fetch_template($template_dir, $type, $params = null) { if (!empty($params) && is_array($params)) { extract($params); } $template = wqp_get_query_template($template_dir, $type); if (file_exists($template)) { ob_start(); include($template); $contents = ob_get_contents(); ob_end_clean(); } else { $contents = ''; } return $contents; } function wqp_plugins_loaded() { WQP_Factory::add_quiz_type('personality', 'Personality', 'WQP_Quiz_Personality', dirname(__FILE__) . '/quizzes/personality.php'); do_action('wqp_register_quiz_types');" I might have to add an nlbr somewhere or something??? Let me know how to proceed. Thanks!!! " Hey all I have an error in my Facebook application and I'm not sure what's wrong (New to PHP). The error output is: Code: [Select] Warning: array_rand() [function.array-rand]: Second argument has to be between 1 and the number of elements in the array in /home/app/view.php on line 15 And the PHP lines are as follows: $friends = $facebook->api('/me/friends'); print_r(array_rand($friends, 3)); Hi all, this is my first time on this forum! I have a background with HTML and CSS but have recently started a Masters in Computer Science hoping to come out of it with the tools to get a job with PHP development. Our first assignment has somewhat 'thrown me in the deep end' as we have to construct a search engine that indexes the words of a number of documents and rank them using the TF*IDF algorithm along with the log rule associated with Information retrieval. I am completely new to PHP so the past week has been something of a crash course - This is the code I have so far: Code: [Select] <?php $filename = 'airlines.txt'; $fp = fopen( $filename, 'r' ); $file_contents = fread( $fp, filesize( $filename ) ); fclose( $fp ); //$new_contents = ereg_replace("[^A-Za-z0-9]", "", $file_contents); /*$file_contents = trim($file_contents); $file_contents = preg_replace('/\h+/', ' ', $file_contents); $file_contents = preg_replace('/\v{3,}/', PHP_EOL.PHP_EOL, $file_contents); */ $pat[0] = "/^\s+/"; $pat[1] = "/\s{2,}/"; $pat[2] = "/\s+\$/"; $rep[0] = ""; $rep[1] = " "; $rep[2] = ""; $new_contents = preg_replace("/[^A-Za-z0-9\s\s+]/","",$file_contents); $new_contents = preg_replace($pat,$rep,$new_contents); //preg_replace('~\s{2,}~', ' ', $text); $commonWords = array('a','able','about','above'........and another few hundreds cut out of this not to hurt your eyes!); $lines = explode ( "\n", $new_contents); $lines2 = implode (" ", $lines); $words = explode ( " ", $lines2 ); $useful_words = array_diff( $words, $commonWords ); /*for($i = 0; $i < count($lines); $i++) { echo "Piece $i = $lines[$i] <br />"; }*/ for($i = 0; $i < count($useful_words); $i++) { echo "Words $i = $useful_words[$i] <br />"; } //$arr=array("blah1","blah2","blah3"); file_put_contents("demo2.txt",implode(" ",$useful_words)); //$file_c = file_get_contents("demo.txt"); //$colms = explode(",",trim($file_c)); //print_r($colms); //echo $lines[2]; ?> I've got to the stage where that strips out most of the stop words when the final array is printed, but they have been replaced with spaces or something that I have not come acoss because as you may see I had a bit of trouble originally stripping the punctuation marks. I'm hoping someone can point me in the direction as to how to organise the words I have left after the stripping of stop words which are of no use during the search. I need to store those words into another array and index them which says how many times they appear in that document. I've come across the function array array_count_values ( array $input ) on the manual but I'm not sure about the best way to use it. I've attached the files I've used if that helps. Any help would be greatly appreciated! Could anyone help me please. I am trying to create a quiz in (quiz.php) which is works fine, but when I am trying to correct the quiz in another page (result.php) I had an error. I think the problem with posted answers and I couldn't solve it.
This is my code in (quiz.php):
<form method="post" action="result.php"> <?php session_start(); $questionNumber = 1; $query = mysql_query("SELECT * FROM Question WHERE TID = 'TEST' order by RAND()"); while ($result = mysql_fetch_array($query)) { ?> <?php echo $questionNumber . ") " . $result['Question'] . "<br>"; ?> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="A"> <?php echo $result['A']; ?> <br> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="B"> <?php echo $result['B']; ?> <br> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="C"> <?php echo $result['C']; ?> <br> <input type="radio" name="answer<?php echo $result["QID"] ?>" value="D"> <?php echo $result['D']; ?> <br> <?php $questionNumber +=1; } ?> <input type="submit" name="checkQuiz" value="Check Quiz" onclick="location.href='result.php'" /> </form>And This is my code in (result.php): <?php if(isset($_POST['checkQuiz'])) { $correctAnswers = 0; $wrongAnswers = 0; $idList = join (',', array_map('intval', array_keys($_POST['answer']))); $sql = "SELECT QID, Answers FROM correct WHERE QID IN ($idList)"; while (list($QID, $correct) = mysql_fetch_row($res)) { if ($correct == $_POST['answer'][$QID]) { $correctAnswers +=1; } else { $wrongAnswers +=1; } } } ?> // in the body <?php $numberOfQs = $correctAnswers + $wrongAnswers; $score = round(($correctAnswers / $numberOfQs) * 100); ?> Correct Answers: <?php echo $correctAnswers; ?> <br> Wrong Answers: <?php echo $wrongAnswers; ?> <br> Sco <?php echo $score; ?> Hi people. I'm building a quiz with one correct answer out of possible 4. My problem is that after I choose a random answer (which is the correct one) I have problems with choosing random 3 wrong answers which are not the same as answer 1 (they all come from the same table). My first mysql query gives me back 1 row my second mysql query gives me back 15 row (there were 16 - 1 which is the correct one). How can take only 3 rows out of that second query and output them into variables that I can later echo into a form? Can you help me understand this problem or can you propose an alternative method to deal with this? Here are my two queries: Code: [Select] // Fetch random answer (correct) $query = "SELECT * FROM psychofarm_brand WHERE `id`=".$randomNumber; $result = mysql_query($query); $row = mysql_fetch_array($result); // Fetch wrong answer $query2 = "SELECT * FROM psychofarm_gen WHERE `id`!=".$randomNumber; $result2 = mysql_query($query2); $row2 = mysql_fetch_array($result2); I hope this is clear. Thanks I am building program to manage payment/monthly payments. I've ran into an issue that I haven't been able to overcome and need some help. I've been lurking for a while and decided it was time to ask you guys...Here's the issue: I have a table 'payments' that contains scheduled payments that looks like: id clientid paymentduedate balance expected pending 367 112233 4/16/2011 1030.00 257.50 Y 368 112233 5/16/2011 1030.00 257.50 Y 369 112233 6/16/2011 1030.00 257.50 Y 370 112233 7/16/2011 1030.00 257.50 Y What I need to do that I haven't figured out is to adjust the expected amount according to the payment, update the status to N (not pending) without affecting the later expected payments. For example: they make a payment of $257.50, applies that to row 367, sets the status to N, but leaves the other status' to Y (for obvious reasons). the make a payment of $250.00, leaving the balance at $7.50, so lets add $7.50 to row 368, mark 367 status to N the make a payment of $300.00, leaving the expected balance at $0.00 for row 367, but adjust the balance for row 368 to $215.00 Any ideas? Thanks Hi, I need to develop a module called chat with doctor. User can able to chat with the doctor for that he has to pay some amount to website. Say example user got purchase the Package worth : 2$ =>5min. After 5 min chat will be closed , timer should be shown while chatting. How can we do this? I've made a code here.. It can create a quiz. It consist of a question and a 4 choices.. But my problem here is. when i inserted only 2 values for the choices, there would still be 4 radio button(Choices). Can someone help me. i want my code to be like : When user inputs 4 values. there would be 4 choices, but when user insert 2 values, there would be 2 values.. Here's my code for the form Code: [Select] <form name="formupload" method="post" action="setdate.php"> <div id="apDiv10"><input type="image" src="images/setdate.png" name="Image9" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="valdeactiveass.php"> <div id="apDiv8"><input type="image" src="images/deacass.png" name="Image9" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="valactiveass.php"> <div id="apDiv7"><input type="image" src="images/activeass.png" name="Image9" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="quiz_preview.php"> <div id="apDiv3"><input type="image" src="images/preview.png" name="Image9" width="170" height="35" border="0" ></div> </form> <form name="form2" method="post" action="delques.php"> <div id="apDiv9"><input type="image" src="images/delques.png" name="Image8" width="170" height="35" border="0" ></div> </form><form name="formupload" method="post" action="validatequiz.php"> <input type="text" style="position:absolute; top:160px; left:101px; width: 576px; height: 31px; font-size:10px;" name="question" id="question" /> <input type="text" style="position:absolute; top:244px; left:109px; width: 567px; height: 19px; font-size:10px;" name="c1" id="c1" /> <input type="text" style="position:absolute; top:297px; left:108px; width: 567px; height: 19px; font-size:10px;" name="c2" id="c2" /> <input type="text" style="position:absolute; top:350px; left:109px; width: 567px; height: 19px; font-size:10px;" name="c3" id="c3" /><input type="text" style="position:absolute; top:396px; left:110px; width: 567px; height: 19px; font-size:10px;" name="c4" id="c4" /> <select style="position:absolute; top:463px; left:309px; width: 80px; height: 23px; font-size:10px;" name="answer" id="answer"> <option value="Select">Select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select><div id="apDiv2"><input type="image" src="images/submit.png" name="Image8" width="170" height="35" border="0" ></div> </form> And this of the quiz maker.. Code: [Select] <?php if (isset($_POST['sent'])) { for ($i=0;$i<count($questions);$i++) { if ($_POST['q2'.$i]=="w") { $score++; } else { } } $percent = number_format(($score/count($questions))*100,2,".",","); echo("<br>".$score." out of ".count($questions)." (".$percent."% right)<br>\n"); } else { echo("<form action=\"#\" method=\"post\">\n"); echo("<input type=\"hidden\" name=\"sent\">\n"); for ($i=0;$i<count($questions);$i++) { echo("<b>".$questions[$i][0]."</b><br><br>\n"); if ($questions[$i][5]==1) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][1]."<br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][1]."<br>\n"); } if ($questions[$i][5]==2) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][2]."<br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][2]."<br>\n"); } if ($questions[$i][5]==3) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][3]."<br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][3]."<br>\n"); } if ($questions[$i][5]==4) { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"c\"> ".$questions[$i][4]."<br><br>\n"); } else { echo("<input type=\"radio\" name=\"q2".$i."\" value=\"w\"> ".$questions[$i][4]."<br><br>\n"); } } echo("<input type=\"submit\" value=\"Submit Exam\"></form>"); } ?> |