Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] problem z T_ELSE
powertee
post 26.03.2008, 12:18:02
Post #1





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 13.12.2007
Skąd: Katowice/Goleniowy

Ostrzeżenie: (0%)
-----


Wywala mi błąd:
Parse error: syntax error, unexpected T_ELSE in C:\myphp\lol.php on line 28
wcześniej działało ale pewnie coś usunąłem i przestało....

  1. <?php
  2.  
  3. $form_error = array();
  4. $errorlist = false;
  5.  
  6.  function add_error($error) {
  7.  global $errorlist, $form_error;
  8.  $errorlist = true;
  9.  $form_error[] = $error;
  10.  }
  11.  
  12. function _process_form($method) {
  13. if(function_exists("process_form")) {
  14. $data = $method;
  15. foreach($data as $key=>$val) {
  16.  if(preg_match("/(submit | required))|(_desc$)/i". $key) == 1)
  17.  unset($data[$key]);
  18. }
  19.  process_form($data);
  20. }
  21. }
  22. function validate_form($method) {
  23. $process = true;
  24.  if(!isset($method['required'])) 
  25. add_error("Nie można odszukać wymaganego pola ukrytego o nazwie 'required'!");
  26. $process = false;
  27. } else 
  28. {
  29.  $required = explode('.',$method['required']);
  30. foreach($required as $val) {
  31. if(empty($method[$val])) {
  32. if(isset($method[$val."_desc"])) {
  33. $errormsg = "Nie podano wartości pola wymaganego '{$method[$val."_desc"]}'!";
  34. } 
  35. else 
  36. {
  37. $errormsg = "Wymagane pole '$val' jest puste!";
  38. }
  39. add_error($errormsg);
  40. $process = false;
  41. }
  42.  }
  43.  
  44.  foreach($method as $key=>$val) {
  45. if(preg_match("/(submit | required)|(_desc$)/i", $key) !=1) {
  46.  $func = $key."_validate";
  47. if(function_exists($func)) {
  48. if(!isset($method[$key."_desc"])) {
  49.  $result = $func($val. $key);
  50. } else {
  51. $result = $func($val, $method[$key. "_desc"]);
  52. }
  53. if($result !== true) {
  54. add_error($result);
  55. $process = false;
  56. }
  57. }
  58. }
  59. }
  60. }
  61.  if($process) {
  62. _process_form($method);
  63.  return true;
  64. }
  65. return false;
  66. }
  67.  $method = &$_GET;
  68. if(isset($method['submit'])) {
  69. validate_form($method);
  70. }
  71. function email_validate($data, $desc) {
  72. $regex = "/^([a-zA-Z0-9.-_]+)@({[a-zA-Z0-9-]+.}+[a-zA-Z0-9-]+)$/";
  73. if(preg_match($regex, $data) !=1)
  74. return "Wartość pola '$desc' jest nieprawidłowa.";
  75. return true;
  76. }
  77. function process_form($data) {
  78. $msg = "W formularzu ze strony {$_SERVER['PHP_SELF']} zostały podane następujące wartości: \n\n";
  79. foreach($data as $key=>$val) {
  80. $msg .= "$key => $val\n";
  81. }
  82. mail("dodaj.php", "Wykonane", $msg);
  83.  }
  84.  
  85. ?>
  86.  
  87. <HTML>
  88. <HEAD>
  89. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
  90. <TITLE>Przykład weryfikacji formularza</TITLE>
  91. </HEAD>
  92. <BODY>
  93.  
  94. <?php
  95.  if($errorlist): ?>
  96.  Proszę poprawić następujące błędy:<BR>
  97.  <UL>
  98.  <?php foreach($form_error as $val): ?>
  99.  <LI><?=$val?>
  100.  <?php endforeach; ?>
  101.  </UL>
  102. <?php endif; ?>
  103.  
  104.  
  105. <FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD=GET>
  106. <INPUT TYPE="hidden" NAME="required" VALUE="first.last.email">
  107. <INPUT TYPE="hidden" NAME="submit" VALUE="1">
  108. <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
  109. <TR>
  110. <TD COLSPAN=2>Proszę wypełnić następujące pola. (* = Wymagane)</TD>
  111. </TR>
  112. <TR>
  113. <TD>*Imię:</TD>
  114. <TD><INPUT TYPE="text" NAME="first" VALUE="<?php echo @$method['first']; ?>">
  115. <INPUT TYPE="hidden" NAME="last_desc" VALUE="Imię"></TD>
  116. </TR>
  117. <TR>
  118. <TD>*Nazwisko:</TD>
  119. <TD><INPUT TYPE="text" NAME="last" VALUE="<?php echo @$method['last']; ?>">
  120. <INPUT TYPE="hidden" NAME="last_desc" VALUE="Nazwisko"></TD>
  121. </TR>
  122. <TR>
  123. <TD>Telefon:</TD>
  124. <TD><INPUT TYPE="text" NAME="phone" VALUE="<?php echo @$method['phone']; ?>">
  125. <INPUT TYPE="hidden" NAME="phone_desc" VALUE="Numer telefonu"></TD>
  126. </TR>
  127. <TR>
  128. <TD>*Email</TD>
  129. <TD><INPUT TYPE="text" NAME="email" VALUE="<?php echo @$method['email']; ?>">
  130. <INPUT TYPE="hidden" NAME="email_desc" VALUE="Adres email"></TD>
  131. </TR>
  132. <TR>
  133. <TD COLSPAN=2><INPUT TYPE="submit" VALUE="Wyślij"></TD>
  134. </TR>
  135. </TABLE>
  136. </FORM>
  137.  
  138. </BODY>
  139. </HTML>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Pilsener
post 26.03.2008, 12:29:41
Post #2





Grupa: Zarejestrowani
Postów: 1 590
Pomógł: 185
Dołączył: 19.04.2006
Skąd: Gdańsk

Ostrzeżenie: (0%)
-----


  1. <?php
  2. }
  3. }
  4. }
  5. }
  6. }
  7. ?>
- stosuj wcięcia i komentarze. Skąd mam teraz wiedzieć, gdzie zgubiłeś {? A może masz o jeden za dużo? Otwierający czy zamykający? Gdzieś tu był temat z edytorami do kodu PHP - ktoś reklamował taki, który koloruje (czy jakoś tam inaczej wizualizuje) klamerki.
Go to the top of the page
+Quote Post
powertee
post 26.03.2008, 12:37:40
Post #3





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 13.12.2007
Skąd: Katowice/Goleniowy

Ostrzeżenie: (0%)
-----


ok już zmalazłem
  1. <?php
  2. if(!isset($method['required'])) {
  3. ?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 19:45