Search the Community
Showing results for tags 'php html forms'.
-
I have a text file that contains questions and answers: $string = '1) The most important feature of spiral model is: requirement analysis. Risk management. quality management. configuration management 2) The worst type of coupling is: Data coupling. control coupling. stamp coupling. content coupling 3) One of the fault base testing techniques is: Unit testing. beta testing. Stress testing. mutation testing 4) A fault simulation testing technique is: Mutation testing. Stress testing. Black box testing. White box testing. 5) RS is also known as specification of: White box testing. Stress testing. Integrated testing. Black box testing 6) Which of these terms is a level name in the Capability Maturity Model?: Ad hoc. Repeatable. Reusable. Organized 7) FP-based estimation techniques require problem decomposition based on?: Information domain values. project schedule. software functions. process activities What types of models are created during software requirements analysis?: Functional and behavioral. Algorithmic and data structure. Architectural and structural. Usability and reliability 9) Which of the following is not an attribute of software engineering: Efficiency. Scalability. Dependability. Usability' and the following code reads from the text file and puts in an html form format which can be posted: <html> <head> <style> #text_disabled{ border:0; font-size:10pt; color:black; } </style> <title>Question and Answer Read From Text File</title> </head> <body> <form action="processor.php" method="POST" align="center"> <b><u> QUESTIONS AND ANSWERS QUIZ</u></b> <br /><br /> <?php $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); $string = fread($openFile, filesize("questionandanswers.txt")); //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; preg_match('/\d.*/', $string, $match); //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; preg_match_all('/\d\D*/', $match[0], $results); $qas = array(); // We prepare an array that will store the questions/answers foreach($results[0] as $result) { //Separating the question from the string with all the answers. list($question, $all_answers) = explode(':', $result); //Separating the different answers $answers_array = explode('.', $all_answers); //Storing the question and the array with all the answers into the previously prepared array; $qas[] = array('question' => $question, 'answers' => $answers_array); } //Looping through the array and outputting all the info into a form; foreach($qas as $k=>$v) { echo "<input id='text_disabled' style='width:40%' type='text' value='".$v['question']."' name='questions[]' disabled>"; echo "<select name='selected_answers[]'>"; foreach($v['answers'] as $answer){ echo "<option value='".$answer."'>".$answer."</option>"; } echo "</select>"; echo "<br/><br/>"; } ?> <input name= "submit" type="submit" value="Submit Answers">  <input type="reset" value ="Clear Answers"> </form> </body> </html> The problem is with the processor.php page which does not display the posted questions and answers and also does not compute the total score from the answers selected. these are the codes. <pre> <?php $score = $score1 = $score2 = $score3 = $score4 = $score5 = $score6 = $score7 = $score8 = 0; if (isset($_POST['submit'])) { $answers = $_POST['selected_answers']; echo '<br />'; //First question if ($answers[0]=="risk management") { $score++; } elseif($answers[0]=="quality management") { $score--; } elseif($answers[0]=="configuration management") { $score --; } else { print_r($answers[0]); } echo '<br />'; //Second question if ($answers[1]=="Data coupling") { $score1 =1; } elseif($answers[1]=="Control coupling") { $score1 =0; } elseif($answers[1]=="Stamp coupling") { $score1 =0; } else { print_r($answers[1]); } echo '<br />'; //third question if ($answers[2]=="Unit testing") { $score2 =1; } elseif($answers[2]=="Beta testing") { $score2 =0; } elseif($answers[2]=="Stress testing") { $score2 =0; } else { print_r($answers[2]); } echo '<br />'; //fourth question if ($answers[3]=="Mutation testing") { $score3 =1; } elseif($answers[3]=="Stress testing") { $score3 =0; } elseif($answers[3]=="Black box testing") { $score3 =0; } else { print_r($answers[3]); } echo '<br />'; //fifth question if ($answers[4]=="white box testing") { $score4 =1; } elseif($answers[4]=="Stress testing") { $score4 =0; } elseif($answers[4]=="integrated testing") { $score4 =0; } else { print_r($answers[4]); } echo '<br />'; //sixth question if ($answers[5]=="Ad hoc") { $score5 =1; } elseif($answers[5]=="Repeatable") { $score5 =0; } elseif($answers[5]=="Reusable") { $score5 =0; } else { print_r($answers[5]); } echo '<br />'; //seventh question if ($answers[6]=="information domain values") { $score6 =1; } elseif($answers[6]=="project schedule") { $score6 =0; } elseif($answers[6]=="software function") { $score6 =0; } else { print_r($answers[6]); } echo '<br />'; //eigth question if ($answers[7]=="Functional and behavioral") { $score7 =1; } elseif($answers[7]=="Algorithmic and data structure") { $score7 =0; } elseif($answers[7]=="Architectural and structural") { $score7 =0; } else { print_r($answers[7]); } echo '<br />'; //nineth question if ($answers[8]=="Efficiency") { $score8 =1; } elseif($answers[8]=="Scalability") { $score8 =0; } elseif($answers[8]=="Dependability") { $score8 =0; } else { print_r($answers[8]); } } //code to generate the total score echo '<br />'; $Total = $score + $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8; echo '<br />'; echo '<b>Your Total score is: $Total </b>'; ?> </pre> What might be the problem. kindly assist me crack this out. Thank you.