Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP]błąd w php
Forum PHP.pl > Forum > Przedszkole
hhuubbeerrtt00
Hej,
mam zrobiony quzi, ale pojawai się błąd Notice: Undefined variable: DisabledRadio in C:\xampp\htdocs\quiz\oracz-test.php on line 89oraz Notice: Undefined variable: out in C:\xampp\htdocs\quiz\oracz-test.php on line 102 . Nie wiem gdzie jest błąd heelp. A to kod:
  1. <?php
  2. define('BR', "\r\n");
  3.  
  4. class Point
  5. {
  6. var $Question;
  7. var $Options;
  8. var $Answer;
  9. }
  10.  
  11. class Test
  12. {
  13. var $TestName = 'Test językowy';
  14. var $PageName = 'strona';
  15. var $ResultsName = 'wyniki testu';
  16. var $PrevPageButtonName = '< cofnij';
  17. var $NextPageButtonName = 'dalej >';
  18. var $CheckButtonName = 'sprawdź test';
  19. var $ShowAnswersButtonName = 'zobacz odpowiedzi';
  20. var $CorrectAnswersName = 'dobrze';
  21. var $WrongAnswersName = 'źle';
  22. var $BlankAnswersName = 'brak';
  23.  
  24. var $CorrectAnswersColor = '#02a629';
  25. var $WrongAnswersColor = '#e51c01';
  26. var $BlankAnswersColor = '#ccc';
  27.  
  28. var $AnswersPercentLenght = 200;
  29. var $Points;
  30. var $PointsPerPage = 5;
  31. var $PageNr;
  32. var $TmpAnswers;
  33. var $Answers;
  34.  
  35. var $CorrectAnswers;
  36. var $CorrectAnswersPercent;
  37. var $WrongAnswers;
  38. var $WrongAnswersPercent;
  39. var $BlankAnswers;
  40. var $BlankAnswersPercent;
  41.  
  42. function CountPages() {
  43. return ceil($this->CountPoints() / $this->PointsPerPage);
  44. }
  45.  
  46. function CountPoints() {
  47. return count($this->Points);
  48. }
  49.  
  50. function NewPoint($Question, $Options, $Answer) {
  51.  
  52. $Nr = $this->CountPoints() + 1;
  53. $this->Points[$Nr] = new Point;
  54. $this->Points[$Nr]->Question = $Question;
  55. $this->Points[$Nr]->Options = $Options;
  56. $this->Points[$Nr]->Answer = $Answer;
  57.  
  58. }
  59.  
  60. function ViewPoint($Nr, $SelectedOption, $SelectRightAnswer) {
  61.  
  62. if (($Nr <= $this->CountPoints()) && ($Nr > 0)) {
  63. $out = '<li class="point">'.BR;
  64. $out .= $this->Points[$Nr]->Question.BR;
  65. $out .= '<ul>'.BR;
  66.  
  67. foreach ($this->Points[$Nr]->Options as $Key => $Option) {
  68.  
  69. $Key = $Key + 1;
  70. $out .= '<li';
  71.  
  72. if ($SelectRightAnswer > 0) {
  73.  
  74. $DisabledRadio = 'disabled="disabled" ';
  75.  
  76. if ($Key == $SelectRightAnswer)
  77. $out .= ' class="right-answer" style="color:'.$this->CorrectAnswersColor.'"';
  78. elseif ($Key == $SelectedOption)
  79. $out .= ' class="wrong-answer" style="color:'.$this->WrongAnswersColor.'"';
  80. }
  81.  
  82. if ($SelectedOption == $Key)
  83. $CheckedRadio = 'checked="checked" ';
  84. else
  85. $CheckedRadio = '';
  86.  
  87. $out .= '><input type="radio" '.$DisabledRadio.'id="r'.$Nr.$Key.'" name="'.$Nr.'" value="'.$Key.'" '.$CheckedRadio.'/>';
  88. $out .= '<label for="r'.$Nr.$Key.'">'.$Option.'</label></li>'."\r\n";
  89. }
  90. $out .= '</ul>'.BR;
  91. $out .= '</li>'."\r\n";
  92. return $out;
  93. }
  94. }
  95.  
  96. function ViewCustomList($FromNr, $NrOfPoints) {
  97.  
  98. for ($i = $FromNr; $i < $FromNr+$NrOfPoints; $i++)
  99. if ($this->Answers == '')
  100. $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], 0);
  101. else
  102. $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], $this->Points[$i]->Answer);
  103.  
  104. return $out;
  105. }
  106.  
  107. function TakePost() {
  108. if (isset($_POST['PageNr'])) {
  109. # zbieranie odpowiedzi
  110. if (isset($_POST['TmpAnswers'])) {
  111.  
  112. $this->TmpAnswers = $_POST['TmpAnswers'];
  113.  
  114. if (!isset($_POST['Answers'])) {
  115.  
  116. $FromNr = ($_POST['PageNr'] - 1) * $this->PointsPerPage + 1;
  117.  
  118. if ($_POST['PageNr'] == $this->CountPages())
  119. $NrOfPoints = $this->CountPoints() - $FromNr + 1;
  120. else
  121. $NrOfPoints = $this->PointsPerPage;
  122.  
  123. for ($i = $FromNr; $i < $FromNr + $NrOfPoints; $i++) {
  124.  
  125. if ($_POST[$i] == '')
  126. $this->TmpAnswers[$i - 1] = '0';
  127. else
  128. $this->TmpAnswers[$i - 1] = $_POST[$i];
  129. }
  130. }
  131. }
  132.  
  133. # naciśnięcie przycisku NextPage
  134. if (isset($_POST['NextPage'])) {
  135.  
  136. if ($this->CountPages() > $_POST['PageNr'])
  137.  
  138. $this->PageNr = $_POST['PageNr'] + 1;
  139.  
  140. else
  141.  
  142. $this->PageNr = 1;
  143. }
  144.  
  145. # naciśnięcie przycisku PrevPage
  146. if (isset($_POST['PrevPage'])) {
  147.  
  148. if ($_POST['PageNr'] > 1)
  149.  
  150. $this->PageNr = $_POST['PageNr'] - 1;
  151.  
  152. else
  153.  
  154. $this->PageNr = $this->CountPages();
  155. }
  156.  
  157. } else {
  158.  
  159. # wielkości startowe
  160. $this->PageNr = 1;
  161.  
  162. if (isset($_POST['TmpAnswers']))
  163. $this->TmpAnswers = $_POST['TmpAnswers'];
  164. else
  165. for ($i = 1; $i <= $this->CountPoints(); $i++)
  166. $this->TmpAnswers .= '0';
  167. }
  168.  
  169. #pobierz czy jest odpowiedz
  170. if (isset($_POST['Answers'])) {
  171.  
  172. $this->Answers .= $_POST['Answers'];
  173. }
  174. }
  175.  
  176. #sprawdź odpowiedzi
  177. function CheckAnswers() {
  178.  
  179. $this->CorrectAnswers = 0;
  180. $this->BlankAnswers = 0;
  181.  
  182. for ($i = 1; $i <= $this->CountPoints(); $i++) {
  183. if ($this->TmpAnswers[$i - 1] == $this->Points[$i]->Answer) $this->CorrectAnswers += 1;
  184. if ($this->TmpAnswers[$i - 1] == '0') $this->BlankAnswers += 1;
  185. }
  186.  
  187. $this->WrongAnswers = $this->CountPoints() - ($this->CorrectAnswers + $this->BlankAnswers);
  188.  
  189. $CAP = $this->CorrectAnswers/$this->CountPoints()*1000;
  190. $WAP = $this->WrongAnswers/$this->CountPoints()*1000;
  191. $BAP = $this->BlankAnswers/$this->CountPoints()*1000;
  192.  
  193. $this->CorrectAnswersPercent = round($CAP) / 10;
  194. $this->WrongAnswersPercent = round($WAP) / 10;
  195. $this->BlankAnswersPercent = round($BAP) / 10;
  196. }
  197.  
  198.  
  199. function ViewTest() {
  200.  
  201. $this->TakePost();
  202.  
  203. if (isset($_POST['Check'])) {
  204.  
  205. # formularz wyników
  206.  
  207. $this->CheckAnswers();
  208.  
  209. $out = '<form id ="test" action="" method="post">'.BR;
  210. $out .= '<fieldset>'.BR;
  211. $out .= '<legend>'.$this->TestName.' ['.$this->ResultsName.']</legend>'.BR;
  212. $out .= '<ul id="results">'.BR;
  213.  
  214. $CorrectAnswersLenght = round($this->AnswersPercentLenght*$this->CorrectAnswersPercent/100) + 1;
  215. $WrongAnswersLenght = round($this->AnswersPercentLenght*$this->WrongAnswersPercent/100) + 1;
  216. $BlankAnswersLenght = round($this->AnswersPercentLenght*$this->BlankAnswersPercent/100) + 1;
  217.  
  218. $out .= '<li id="CorrectAnswers" style="border-left:'.$CorrectAnswersLenght.'px solid '.$this->CorrectAnswersColor.'">'.$this->CorrectAnswers.' '.$this->CorrectAnswersName.' ('.$this->CorrectAnswersPercent.'%)</li>'.BR;
  219. $out .= '<li id="WrongAnswers" style="border-left:'.$WrongAnswersLenght.'px solid '.$this->WrongAnswersColor.'">'.$this->WrongAnswers.' '.$this->WrongAnswersName.' ('.$this->WrongAnswersPercent.'%)</li>'.BR;
  220. $out .= '<li id="BlankAnswers" style="border-left:'.$BlankAnswersLenght.'px solid '.$this->BlankAnswersColor.'">'.$this->BlankAnswers.' '.$this->BlankAnswersName.' ('.$this->BlankAnswersPercent.'%)</li>'.BR;
  221. $out .= '</ul>'.BR;
  222. $out .= '<input type="hidden" name="TmpAnswers" value="'.$this->TmpAnswers.'" />'.BR;
  223. $out .= '<input type="hidden" name="Answers" value="Check" />'.BR;
  224. $out .= '<div id="buttons">'.BR;
  225. $out .= '<input type="submit" id="ShowAnswers" name="ShowAnswers" value="'.$this->ShowAnswersButtonName.'" />'.BR;
  226. $out .= '</div>'.BR;
  227. $out .= '</fieldset>'.BR;
  228. $out .= '</form>'.BR;
  229.  
  230. } else {
  231.  
  232. #formularz pytań i odpowiedzi
  233.  
  234. $out = '<form id ="test" action="" method="post">'.BR;
  235. $out .= '<fieldset>'.BR;
  236. $out .= '<legend>'.$this->TestName.' ['.$this->PageName.' '.$this->PageNr.'/'.$this->CountPages().']</legend>'.BR;
  237. $out .= '<ul>'.BR;
  238. $out .= $this->ViewCustomList(($this->PageNr - 1) * $this->PointsPerPage + 1, $this->PointsPerPage);
  239. $out .= '</ul>'.BR;
  240. $out .= '<input type="hidden" name="TmpAnswers" value="'.$this->TmpAnswers.'" />'.BR;
  241. if ($this->Answers != '') $out .= '<input type="hidden" name="Answers" value="'.$this->Answers.'" />'.BR;
  242. $out .= '<input type="hidden" name="PageNr" value="'.$this->PageNr.'" />'.BR;
  243. $out .= '<div id="buttons">'.BR;
  244. if ($this->PageNr > 1) $out .= '<input type="submit" id="PrevPage" name="PrevPage" value="'.$this->PrevPageButtonName.'" />'.BR;
  245. if ($this->PageNr < $this->CountPages()) $out .= '<input type="submit" id="NextPage" name="NextPage" value="'.$this->NextPageButtonName.'" />'.BR;
  246. if (($this->PageNr == $this->CountPages()) && ($this->Answers == '')) $out .= '<input type="submit" id="Check" name="Check" value="'.$this->CheckButtonName.'" />'.BR;
  247. $out .= '</div>'.BR;
  248. $out .= '</fieldset>'.BR;
  249. $out .= '</form>'.BR;
  250. }
  251.  
  252. return $out;
  253. }
  254. }
  255.  
  256.  
  257. ?>
Kshyhoo
Niezdefiniowane zmienne "DisabledRadio" i "out". poczytaj o błędach typu "Notice"...
tolomei
Błąd pierwszy:
Linia 80:
  1. }


Zamień na:
  1. } else $DisabledRadio = '';




Błąd drugi:
Linia 100:
  1. $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], 0);


Zamień na:
  1. $out = $this->ViewPoint($i, $this->TmpAnswers[$i - 1], 0);


ORAZ
Linia 102:
  1.  
  2. $out .= $this->ViewPoint($i, $this->TmpAnswers[$i - 1], $this->Points[$i]->Answer);


Zamień na:
  1.  
  2. $out = $this->ViewPoint($i, $this->TmpAnswers[$i - 1], $this->Points[$i]->Answer);


Zastanów się dlaczego tak.
Podpowiem, że chodzi o zasięg zmiennej $out.
Starasz się dopisywać coś na jej końcu kiedy ona jeszcze nie istnieje.
Sprawdź co oznacza zapis ".=" i jaka jest jego dłuższa wersja.

Pozdrawiam.
mat-bi
Ludzie. Błedy mówią same za siebie, forum to nie parser, do cholery!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.