Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Błąd w html podczas wywoływania errora
Forum PHP.pl > Forum > PHP
kiepski96
Witam,otóż mam problem :

Mam kod,dzięki któremu po przekroczeniu określonej liczby rejestracji ( w poniższym przypadku jest 2 ) wyświetla się tekst "Brak nagrody "

Lecz tak nie jest,nie wyświetla się .
Dane do mysql są ok.

Myślę,że coś pochrzaniłem z html.
Czy mógłbym prosić o kod html, który będzie właśnie wyświetlał ten error ?

Oto mój php :

  1. <?php
  2. if (!isset($_SESSION['username']))
  3. {
  4. header('Location: ./login.php');
  5. }
  6. ?>
  7. <?php
  8. $error_message = "";
  9. $action = isset($_POST['action']) ? $_POST['action'] : '';
  10. $mysql_server = 'localhost';
  11. $mysql_username = 'xxx';
  12. $mysql_password = 'xxx';
  13. $mysql_database = 'xxx';
  14. $mysql_table = 'nagroda1';
  15. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  16. mysql_select_db($mysql_database, $db);
  17. $sql = "SELECT id FROM ".$mysql_table;
  18. $result = mysql_query($sql, $db);
  19. $nagroda1=mysql_num_rows($result);
  20.  
  21. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $nagroda1 >= 2 )
  22. {
  23.  
  24. $error_message = "Pula nagród wyczerpana.";
  25. }
  26. ?>
kadlub
  1. echo "Pula nagród wyczerpana.";
  2.  
kiepski96
Czy po bezpośrednim wklejeniu tego do tego skryptu i wzięciu go w divy będzie wszystko ok,czy nie trzeba nic innego dodawać ?
mlawnik
Mysle ze tak, ale sproboj.

Sorry za ort, zaraz zmieniam klawiature.
kadlub
jak chcesz ten cały kod wstawić w div i coś tam jeszcze przed nim wyświetlać to pamiętaj że masz session_start() i ono musi być na początku całego pliku php a i w jednym pliku session_strat() wystarczy tylko raz a ty masz dwa razy niepotrzebnie
kiepski96
Nadal nic. Trochę musiałem zmienić .
Teraz jest php :
  1. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $nagroda1 >= 2 )
  2. {
  3. $error_message1 = 'Pula nagród wyczerpana.';
  4. }
  5. else


A w html :
  1. <div id="Html3" style="position:absolute;left:319px;top:302px;width:134px;height:24px;z-index:16">
  2. <?php echo $error_message1; ?></div>



I nadal nie wyświetla błędu .
Co jest źle ?
kadlub
próbujesz wyświetlić zmienną $error_message1 w osobnym pliku html ?
kiepski96
Wszystko jest w jednym pliku spis.php, tylko daje ten error_message1 z treścią błędu w części php, zamykam ?> i się zaczyna html i tam daje w divy to <?php echo zmienna ?> div . Może to jest tym spowodowane ? Może dać ten div w części php,gdzie jest session start ? Sory, że tak nie dokładnie, ale nie ma mnie w domu .
kadlub
  1. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $nagroda1 >= 3 )



myślę że problem leży w tym if i do tego pliku wysyłasz jeszcze jakieś dane metodą GET i dlatego warunek nie jest spełniony

ja bym zamiast $_SERVER['REQUEST_METHOD']=='POST' dał jakieś pole z formularza np isset($_POST['nazwa przyciku wysyłający formularz'])
kiepski96
Już nie wiem co mam robić. Może dam cały kod :

  1. <?php
  2. if (!isset($_SESSION['username']))
  3. {
  4. header('Location: ./login.php');
  5. }
  6. ?>
  7.  
  8. <?php
  9. $error_message1 = "";
  10. $action = isset($_POST['action']) ? $_POST['action'] : '';
  11. $mysql_server = 'localhost';
  12. $mysql_username = 'xxx';
  13. $mysql_password = 'xxx';
  14. $mysql_database = 'xxx';
  15. $mysql_table = 'nagroda1';
  16. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  17. mysql_select_db($mysql_database, $db);
  18. $sql = "SELECT id FROM ".$mysql_table;
  19. $result = mysql_query($sql, $db);
  20. $nagroda1=mysql_num_rows($result);
  21.  
  22. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $nagroda1 >= 2 )
  23. {
  24. $error_message1 = 'Pula nagród wyczerpana.';
  25. }
  26. else
  27. ?>
  28. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  29. <html>
  30. <head>
  31. <meta http-equiv="Content-Language" content="pl">
  32. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  33. <title>Katalog nagród</title>
  34. <style type="text/css">
  35. div#container
  36. {
  37. width: 1250px;
  38. position: relative;
  39. margin-top: 0px;
  40. margin-left: auto;
  41. margin-right: auto;
  42. text-align: left;
  43. }
  44. </style>
  45. <style type="text/css">
  46. body
  47. {
  48. text-align: center;
  49. margin: 0;
  50. background-color: #FFFFFF;
  51. color: #000000;
  52. }
  53. </style>
  54. <script type="text/javascript">
  55. <!--
  56. function SetImage(id, filename)
  57. {
  58. var elem=document.getElementById(id);
  59. if(elem)
  60. {
  61. elem.src=filename;
  62. }
  63. }
  64. //-->
  65. </script>
  66. </head>
  67. <body>
  68. <div id="container">
  69. <div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:259px;top:295px;width:745px;heigh
    t:884px;text-align:left;z-index:0;">
  70. <img src="images/img0015.png" id="Shape1" alt="" title="" style="border-width:0;width:745px;height:884px"></div>
  71. <div id="wb_Image1" style="margin:0;padding:0;position:absolute;left:254px;top:46px;width:740px;height
    :168px;text-align:left;z-index:1;">
  72. <img src="images/top.bez.png" id="Image1" alt="" border="0" style="width:740px;height:168px;"></div>
  73. <div id="wb_Image2" style="margin:0;padding:0;position:absolute;left:253px;top:0px;width:105px;height:
    45px;text-align:left;z-index:2;">
  74. <a href="./index.html" onmouseover="SetImage('Image2','images/button-niebieski_01.png');return false;" onmouseout="SetImage('Image2','images/przycisk-szary1_01.png');return false;"><img src="images/przycisk-szary1_01.png" id="Image2" alt="" border="0" style="width:105px;height:45px;"></a></div>
  75. <div id="wb_Image3" style="margin:0;padding:0;position:absolute;left:358px;top:0px;width:105px;height:
    45px;text-align:left;z-index:3;">
  76. <a href="./rejestracja.html" onmouseover="SetImage('Image3','images/button-niebieski_02.png');return false;" onmouseout="SetImage('Image3','images/przycisk-szary1_02.png');return false;"><img src="images/przycisk-szary1_02.png" id="Image3" alt="" border="0" style="width:105px;height:45px;"></a></div>
  77. <div id="wb_Image4" style="margin:0;padding:0;position:absolute;left:463px;top:0px;width:105px;height:
    45px;text-align:left;z-index:4;">
  78. <a href="./oferty.html" onmouseover="SetImage('Image4','images/button-niebieski_03.png');return false;" onmouseout="SetImage('Image4','images/przycisk-szary1_03.png');return false;"><img src="images/przycisk-szary1_03.png" id="Image4" alt="" border="0" style="width:105px;height:45px;"></a></div>
  79. <div id="wb_Image5" style="margin:0;padding:0;position:absolute;left:568px;top:0px;width:105px;height:
    45px;text-align:left;z-index:5;">
  80. <a href="./dowody.html" onmouseover="SetImage('Image5','images/button-niebieski_04.png');return false;" onmouseout="SetImage('Image5','images/przycisk-szary1_04.png');return false;"><img src="images/przycisk-szary1_04.png" id="Image5" alt="" border="0" style="width:105px;height:45px;"></a></div>
  81. <div id="wb_Image6" style="margin:0;padding:0;position:absolute;left:673px;top:0px;width:105px;height:
    45px;text-align:left;z-index:6;">
  82. <a href="./zasady.html" onmouseover="SetImage('Image6','images/button-niebieski_05.png');return false;" onmouseout="SetImage('Image6','images/przycisk-szary1_05.png');return false;"><img src="images/przycisk-szary1_05.png" id="Image6" alt="" border="0" style="width:105px;height:45px;"></a></div>
  83. <div id="wb_Image7" style="margin:0;padding:0;position:absolute;left:778px;top:0px;width:105px;height:
    45px;text-align:left;z-index:7;">
  84. <a href="./wyplata.html" onmouseover="SetImage('Image7','images/button-niebieski_06.png');return false;" onmouseout="SetImage('Image7','images/przycisk-szary1_06.png');return false;"><img src="images/przycisk-szary1_06.png" id="Image7" alt="" border="0" style="width:105px;height:45px;"></a></div>
  85. <div id="wb_Image8" style="margin:0;padding:0;position:absolute;left:883px;top:0px;width:105px;height:
    45px;text-align:left;z-index:8;">
  86. <a href="./forum.html" onmouseover="SetImage('Image8','images/button-niebieski_07.png');return false;" onmouseout="SetImage('Image8','images/przycisk-szary1_07.png');return false;"><img src="images/przycisk-szary1_07.png" id="Image8" alt="" border="0" style="width:105px;height:45px;"></a></div>
  87. <div id="wb_Image9" style="margin:0;padding:0;position:absolute;left:354px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:9;">
  88. <a href="./nagroda1.php"><img src="images/godzrestocku.png" id="Image9" alt="" border="0" style="width:154px;height:240px;"></a></div>
  89. <div id="wb_Image10" style="margin:0;padding:0;position:absolute;left:552px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:10;">
  90. <img src="images/javelin30.png" id="Image10" alt="" border="0" style="width:154px;height:240px;"></div>
  91. <div id="wb_Image11" style="margin:0;padding:0;position:absolute;left:750px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:11;">
  92. <img src="images/pktx2.png" id="Image11" alt="" border="0" style="width:154px;height:240px;"></div>
  93. <div id="wb_Image12" style="margin:0;padding:0;position:absolute;left:354px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:12;">
  94. <img src="images/premiumnagrodaeu.png" id="Image12" alt="" border="0" style="width:154px;height:240px;"></div>
  95. <div id="wb_Image13" style="margin:0;padding:0;position:absolute;left:552px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:13;">
  96. <img src="images/premka3.png" id="Image13" alt="" border="0" style="width:154px;height:240px;"></div>
  97. <div id="wb_Image14" style="margin:0;padding:0;position:absolute;left:751px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:14;">
  98. <img src="images/losowygift.png" id="Image14" alt="" border="0" style="width:154px;height:240px;"></div>
  99. <div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:413px;top:234px;width:453px;heigh
    t:52px;text-align:center;z-index:15;">
  100. <img src="images/img0016.png" id="Shape2" alt="" title="" style="border-width:0;width:453px;height:52px"></div>
  101. <div id="Html1" style="position:absolute;left:593px;top:459px;width:222px;height:252px;z-index:16">
  102.  
  103. <div id="Html3" style="position:absolute;left:319px;top:302px;width:134px;height:24px;z-index:16">
  104. <?php echo $error_message1;?></div>
  105.  
  106.  
  107.  
  108.  
  109. </div>
  110. </div>
  111. </body>
  112. </html>
kadlub
  1. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda1 >= 2 )


zmień tak i zobaczymy
kiepski96
Działa, ale teraz chciałem wywołać wiele błędów i nie działa .

Oto kod :

  1. <?php
  2. if (!isset($_SESSION['username']))
  3. {
  4. header('Location: ./login.php');
  5. }
  6. ?>
  7.  
  8. <?php
  9. $error_message1 = "";
  10. $action = isset($_POST['action']) ? $_POST['action'] : '';
  11. $mysql_server = 'localhost';
  12. $mysql_username = 'xxx';
  13. $mysql_password = 'xxx';
  14. $mysql_database = 'xxx';
  15. $mysql_table1 = 'nagroda1';
  16. $mysql_table2 = 'nagroda2';
  17. $mysql_table3 = 'nagroda3';
  18. $mysql_table4 = 'nagroda4';
  19. $mysql_table5 = 'nagroda5';
  20. $mysql_table6 = 'nagroda6';
  21. // Tabele do errorów
  22. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  23. mysql_select_db($mysql_database, $db);
  24. $sql = "SELECT id FROM ".$mysql_table1;
  25. $sql = "SELECT id FROM ".$mysql_table2;
  26. $sql = "SELECT id FROM ".$mysql_table3;
  27. $sql = "SELECT id FROM ".$mysql_table4;
  28. $sql = "SELECT id FROM ".$mysql_table5;
  29. $sql = "SELECT id FROM ".$mysql_table6;
  30. $result = mysql_query($sql, $db);
  31.  
  32. $nagroda1=mysql_num_rows($result);
  33.  
  34. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda1 >= 2 ) // Ilość nagrody 1
  35. {
  36. $error_message1 = 'Brak nagrody';
  37. }
  38. else
  39. // Brak nagrody 1
  40. $nagroda2=mysql_num_rows($result);
  41.  
  42. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda2 >= 2 ) // Ilość nagrody 2
  43. {
  44. $error_message2 = 'Brak nagrody';
  45. }
  46. else
  47. // Brak nagrody 2
  48. $nagroda3=mysql_num_rows($result);
  49.  
  50. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda3 >= 2 ) // Ilość nagrody 3
  51. {
  52. $error_message3 = 'Brak nagrody';
  53. }
  54. else
  55. // Brak nagrody 3
  56.  
  57. $nagroda4=mysql_num_rows($result);
  58.  
  59. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda4 >= 2 ) // Ilość nagrody 4
  60. {
  61. $error_message4 = 'Brak nagrody';
  62. }
  63. else
  64. // Brak nagrody 4
  65.  
  66. $nagroda5=mysql_num_rows($result);
  67.  
  68. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda5 >= 2 ) // Ilość nagrody 5
  69. {
  70. $error_message5 = 'Brak nagrody';
  71. }
  72. else
  73. // Brak nagrody 5
  74.  
  75. $nagroda6=mysql_num_rows($result);
  76.  
  77. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda6 >= 2 ) // Ilość nagrody 6
  78. {
  79. $error_message6 = 'Brak nagrody';
  80. }
  81. else
  82. // Brak nagrody 6
  83.  
  84. ?>
  85. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  86. <html>
  87. <head>
  88. <meta http-equiv="Content-Language" content="pl">
  89. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  90. <title>Katalog nagród</title>
  91. <style type="text/css">
  92. div#container
  93. {
  94. width: 1250px;
  95. position: relative;
  96. margin-top: 0px;
  97. margin-left: auto;
  98. margin-right: auto;
  99. text-align: left;
  100. }
  101. </style>
  102. <style type="text/css">
  103. body
  104. {
  105. text-align: center;
  106. margin: 0;
  107. background-color: #FFFFFF;
  108. color: #000000;
  109. }
  110. </style>
  111. <script type="text/javascript">
  112. <!--
  113. function SetImage(id, filename)
  114. {
  115. var elem=document.getElementById(id);
  116. if(elem)
  117. {
  118. elem.src=filename;
  119. }
  120. }
  121. //-->
  122. </script>
  123. </head>
  124. <body>
  125. <div id="container">
  126. <div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:259px;top:295px;width:745px;heigh
    t:884px;text-align:left;z-index:0;">
  127. <img src="images/img0015.png" id="Shape1" alt="" title="" style="border-width:0;width:745px;height:884px"></div>
  128. <div id="wb_Image1" style="margin:0;padding:0;position:absolute;left:254px;top:46px;width:740px;height
    :168px;text-align:left;z-index:1;">
  129. <img src="images/top.bez.png" id="Image1" alt="" border="0" style="width:740px;height:168px;"></div>
  130. <div id="wb_Image2" style="margin:0;padding:0;position:absolute;left:253px;top:0px;width:105px;height:
    45px;text-align:left;z-index:2;">
  131. <a href="./index.html" onmouseover="SetImage('Image2','images/button-niebieski_01.png');return false;" onmouseout="SetImage('Image2','images/przycisk-szary1_01.png');return false;"><img src="images/przycisk-szary1_01.png" id="Image2" alt="" border="0" style="width:105px;height:45px;"></a></div>
  132. <div id="wb_Image3" style="margin:0;padding:0;position:absolute;left:358px;top:0px;width:105px;height:
    45px;text-align:left;z-index:3;">
  133. <a href="./rejestracja.html" onmouseover="SetImage('Image3','images/button-niebieski_02.png');return false;" onmouseout="SetImage('Image3','images/przycisk-szary1_02.png');return false;"><img src="images/przycisk-szary1_02.png" id="Image3" alt="" border="0" style="width:105px;height:45px;"></a></div>
  134. <div id="wb_Image4" style="margin:0;padding:0;position:absolute;left:463px;top:0px;width:105px;height:
    45px;text-align:left;z-index:4;">
  135. <a href="./oferty.html" onmouseover="SetImage('Image4','images/button-niebieski_03.png');return false;" onmouseout="SetImage('Image4','images/przycisk-szary1_03.png');return false;"><img src="images/przycisk-szary1_03.png" id="Image4" alt="" border="0" style="width:105px;height:45px;"></a></div>
  136. <div id="wb_Image5" style="margin:0;padding:0;position:absolute;left:568px;top:0px;width:105px;height:
    45px;text-align:left;z-index:5;">
  137. <a href="./dowody.html" onmouseover="SetImage('Image5','images/button-niebieski_04.png');return false;" onmouseout="SetImage('Image5','images/przycisk-szary1_04.png');return false;"><img src="images/przycisk-szary1_04.png" id="Image5" alt="" border="0" style="width:105px;height:45px;"></a></div>
  138. <div id="wb_Image6" style="margin:0;padding:0;position:absolute;left:673px;top:0px;width:105px;height:
    45px;text-align:left;z-index:6;">
  139. <a href="./zasady.html" onmouseover="SetImage('Image6','images/button-niebieski_05.png');return false;" onmouseout="SetImage('Image6','images/przycisk-szary1_05.png');return false;"><img src="images/przycisk-szary1_05.png" id="Image6" alt="" border="0" style="width:105px;height:45px;"></a></div>
  140. <div id="wb_Image7" style="margin:0;padding:0;position:absolute;left:778px;top:0px;width:105px;height:
    45px;text-align:left;z-index:7;">
  141. <a href="./wyplata.html" onmouseover="SetImage('Image7','images/button-niebieski_06.png');return false;" onmouseout="SetImage('Image7','images/przycisk-szary1_06.png');return false;"><img src="images/przycisk-szary1_06.png" id="Image7" alt="" border="0" style="width:105px;height:45px;"></a></div>
  142. <div id="wb_Image8" style="margin:0;padding:0;position:absolute;left:883px;top:0px;width:105px;height:
    45px;text-align:left;z-index:8;">
  143. <a href="./forum.html" onmouseover="SetImage('Image8','images/button-niebieski_07.png');return false;" onmouseout="SetImage('Image8','images/przycisk-szary1_07.png');return false;"><img src="images/przycisk-szary1_07.png" id="Image8" alt="" border="0" style="width:105px;height:45px;"></a></div>
  144. <div id="wb_Image9" style="margin:0;padding:0;position:absolute;left:354px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:9;">
  145. <a href="./nagroda1.php"><img src="images/godzrestocku.png" id="Image9" alt="" border="0" style="width:154px;height:240px;"></a></div>
  146. <div id="wb_Image10" style="margin:0;padding:0;position:absolute;left:552px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:10;">
  147. <img src="images/javelin30.png" id="Image10" alt="" border="0" style="width:154px;height:240px;"></div>
  148. <div id="wb_Image11" style="margin:0;padding:0;position:absolute;left:750px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:11;">
  149. <img src="images/pktx2.png" id="Image11" alt="" border="0" style="width:154px;height:240px;"></div>
  150. <div id="wb_Image12" style="margin:0;padding:0;position:absolute;left:354px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:12;">
  151. <img src="images/premiumnagrodaeu.png" id="Image12" alt="" border="0" style="width:154px;height:240px;"></div>
  152. <div id="wb_Image13" style="margin:0;padding:0;position:absolute;left:552px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:13;">
  153. <img src="images/premka3.png" id="Image13" alt="" border="0" style="width:154px;height:240px;"></div>
  154. <div id="wb_Image14" style="margin:0;padding:0;position:absolute;left:751px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:14;">
  155. <img src="images/losowygift.png" id="Image14" alt="" border="0" style="width:154px;height:240px;"></div>
  156. <div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:413px;top:234px;width:453px;heigh
    t:52px;text-align:center;z-index:15;">
  157. <img src="images/img0016.png" id="Shape2" alt="" title="" style="border-width:0;width:453px;height:52px"></div>
  158. <div id="Html1" style="position:absolute;left:593px;top:459px;width:222px;height:252px;z-index:16">
  159.  
  160. <div id="brak1" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  161. <?php echo $error_message1;?></div>
  162.  
  163. <div id="brak2" style="position:absolute;left:1px;top:76px;width:119px;height:29px;z-index:16">
  164. <?php echo $error_message2;?></div>
  165.  
  166. <div id="brak3" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  167. <?php echo $error_message3;?></div>
  168.  
  169. <div id="brak4" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  170. <?php echo $error_message4;?></div>
  171.  
  172. <div id="brak5" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  173. <?php echo $error_message5;?></div>
  174.  
  175. <div id="brak6" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  176. <?php echo $error_message6;?></div>
  177. </div>
  178. </div>
  179. </body>
  180. </html>


W tych divach 3-6 są złe pozycje,ale nie patrzmy na to .
kadlub
jak wszystkie zapytania ponazywałeś tak samo to nie dziwne że nie działa


$sql1 = "SELECT id FROM ".$mysql_table1;
$sql2 = "SELECT id FROM ".$mysql_table2;
itd
$result1 = mysql_query($sql1, $db);
$result2 = mysql_query($sql2, $db);
itd
kiepski96
Teraz mam kłopot,ponieważ nie chce wyświetlić wszystkich naraz .
Załóżmy,że w nagroda1 przekroczyło dwa ,a w innych nie to się pojawia error.
Ale jak już przekroczy w nagroda2 i w nagroda1 również to wyświetla error brak nagrody 1 ,a drugiej już nie
kadlub
pokaż jak teraz ten twój kod wygląda
kiepski96
Proszę ,cały kod :

  1. <?php
  2. if (!isset($_SESSION['username']))
  3. {
  4. header('Location: ./login.php');
  5. }
  6. ?>
  7.  
  8. <?php
  9. $error_message1 = "";
  10. $action = isset($_POST['action']) ? $_POST['action'] : '';
  11. $mysql_server = 'localhost';
  12. $mysql_username = 'xxx';
  13. $mysql_password = 'xxx';
  14. $mysql_database = 'xxx';
  15. $mysql_table1 = 'nagroda1';
  16. $mysql_table2 = 'nagroda2';
  17. $mysql_table3 = 'nagroda3';
  18. $mysql_table4 = 'nagroda4';
  19. $mysql_table5 = 'nagroda5';
  20. $mysql_table6 = 'nagroda6';
  21. // Tabele do errorów
  22. $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
  23. mysql_select_db($mysql_database, $db);
  24. $sql1 = "SELECT id FROM ".$mysql_table1;
  25. $sql2 = "SELECT id FROM ".$mysql_table2;
  26. $sql3 = "SELECT id FROM ".$mysql_table3;
  27. $sql4 = "SELECT id FROM ".$mysql_table4;
  28. $sql5 = "SELECT id FROM ".$mysql_table5;
  29. $sql6 = "SELECT id FROM ".$mysql_table6;
  30. $result1 = mysql_query($sql1, $db);
  31. $result2 = mysql_query($sql2, $db);
  32. $result3 = mysql_query($sql3, $db);
  33. $result4 = mysql_query($sql4, $db);
  34. $result5 = mysql_query($sql5, $db);
  35. $result6 = mysql_query($sql6, $db);
  36.  
  37. $mysql_table1=mysql_num_rows($result1);
  38.  
  39. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $mysql_table1 >= 2 ) // Ilość nagrody 1
  40. {
  41. $error_message1 = 'Brak nagrody';
  42. }
  43. else
  44. // Brak nagrody 1
  45. $mysql_table2=mysql_num_rows($result2);
  46.  
  47. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $mysql_table2 >= 2 ) // Ilość nagrody 2
  48. {
  49. $error_message2 = 'Brak nagrody2';
  50. }
  51. else
  52. // Brak nagrody 2
  53. $nagroda3=mysql_num_rows($result3);
  54.  
  55. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda3 >= 2 ) // Ilość nagrody 3
  56. {
  57. $error_message3 = 'Brak nagrody';
  58. }
  59. else
  60. // Brak nagrody 3
  61.  
  62. $nagroda4=mysql_num_rows($result4);
  63.  
  64. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda4 >= 2 ) // Ilość nagrody 4
  65. {
  66. $error_message4 = 'Brak nagrody';
  67. }
  68. else
  69. // Brak nagrody 4
  70.  
  71. $nagroda5=mysql_num_rows($result5);
  72.  
  73. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda5 >= 2 ) // Ilość nagrody 5
  74. {
  75. $error_message5 = 'Brak nagrody';
  76. }
  77. else
  78. // Brak nagrody 5
  79.  
  80. $nagroda6=mysql_num_rows($result6);
  81.  
  82. if ($_SERVER['REQUEST_METHOD'] == 'GET' && $nagroda6 >= 2 ) // Ilość nagrody 6
  83. {
  84. $error_message6 = 'Brak nagrody';
  85. }
  86. else
  87. // Brak nagrody 6
  88.  
  89. ?>
  90. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  91. <html>
  92. <head>
  93. <meta http-equiv="Content-Language" content="pl">
  94. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  95. <title>Katalog nagród</title>
  96. <style type="text/css">
  97. div#container
  98. {
  99. width: 1250px;
  100. position: relative;
  101. margin-top: 0px;
  102. margin-left: auto;
  103. margin-right: auto;
  104. text-align: left;
  105. }
  106. </style>
  107. <style type="text/css">
  108. body
  109. {
  110. text-align: center;
  111. margin: 0;
  112. background-color: #FFFFFF;
  113. color: #000000;
  114. }
  115. </style>
  116. <script type="text/javascript">
  117. <!--
  118. function SetImage(id, filename)
  119. {
  120. var elem=document.getElementById(id);
  121. if(elem)
  122. {
  123. elem.src=filename;
  124. }
  125. }
  126. //-->
  127. </script>
  128. </head>
  129. <body>
  130. <div id="container">
  131. <div id="wb_Shape1" style="margin:0;padding:0;position:absolute;left:259px;top:295px;width:745px;heigh
    t:884px;text-align:left;z-index:0;">
  132. <img src="images/img0015.png" id="Shape1" alt="" title="" style="border-width:0;width:745px;height:884px"></div>
  133. <div id="wb_Image1" style="margin:0;padding:0;position:absolute;left:254px;top:46px;width:740px;height
    :168px;text-align:left;z-index:1;">
  134. <img src="images/top.bez.png" id="Image1" alt="" border="0" style="width:740px;height:168px;"></div>
  135. <div id="wb_Image2" style="margin:0;padding:0;position:absolute;left:253px;top:0px;width:105px;height:
    45px;text-align:left;z-index:2;">
  136. <a href="./index.html" onmouseover="SetImage('Image2','images/button-niebieski_01.png');return false;" onmouseout="SetImage('Image2','images/przycisk-szary1_01.png');return false;"><img src="images/przycisk-szary1_01.png" id="Image2" alt="" border="0" style="width:105px;height:45px;"></a></div>
  137. <div id="wb_Image3" style="margin:0;padding:0;position:absolute;left:358px;top:0px;width:105px;height:
    45px;text-align:left;z-index:3;">
  138. <a href="./rejestracja.html" onmouseover="SetImage('Image3','images/button-niebieski_02.png');return false;" onmouseout="SetImage('Image3','images/przycisk-szary1_02.png');return false;"><img src="images/przycisk-szary1_02.png" id="Image3" alt="" border="0" style="width:105px;height:45px;"></a></div>
  139. <div id="wb_Image4" style="margin:0;padding:0;position:absolute;left:463px;top:0px;width:105px;height:
    45px;text-align:left;z-index:4;">
  140. <a href="./oferty.html" onmouseover="SetImage('Image4','images/button-niebieski_03.png');return false;" onmouseout="SetImage('Image4','images/przycisk-szary1_03.png');return false;"><img src="images/przycisk-szary1_03.png" id="Image4" alt="" border="0" style="width:105px;height:45px;"></a></div>
  141. <div id="wb_Image5" style="margin:0;padding:0;position:absolute;left:568px;top:0px;width:105px;height:
    45px;text-align:left;z-index:5;">
  142. <a href="./dowody.html" onmouseover="SetImage('Image5','images/button-niebieski_04.png');return false;" onmouseout="SetImage('Image5','images/przycisk-szary1_04.png');return false;"><img src="images/przycisk-szary1_04.png" id="Image5" alt="" border="0" style="width:105px;height:45px;"></a></div>
  143. <div id="wb_Image6" style="margin:0;padding:0;position:absolute;left:673px;top:0px;width:105px;height:
    45px;text-align:left;z-index:6;">
  144. <a href="./zasady.html" onmouseover="SetImage('Image6','images/button-niebieski_05.png');return false;" onmouseout="SetImage('Image6','images/przycisk-szary1_05.png');return false;"><img src="images/przycisk-szary1_05.png" id="Image6" alt="" border="0" style="width:105px;height:45px;"></a></div>
  145. <div id="wb_Image7" style="margin:0;padding:0;position:absolute;left:778px;top:0px;width:105px;height:
    45px;text-align:left;z-index:7;">
  146. <a href="./wyplata.html" onmouseover="SetImage('Image7','images/button-niebieski_06.png');return false;" onmouseout="SetImage('Image7','images/przycisk-szary1_06.png');return false;"><img src="images/przycisk-szary1_06.png" id="Image7" alt="" border="0" style="width:105px;height:45px;"></a></div>
  147. <div id="wb_Image8" style="margin:0;padding:0;position:absolute;left:883px;top:0px;width:105px;height:
    45px;text-align:left;z-index:8;">
  148. <a href="./forum.html" onmouseover="SetImage('Image8','images/button-niebieski_07.png');return false;" onmouseout="SetImage('Image8','images/przycisk-szary1_07.png');return false;"><img src="images/przycisk-szary1_07.png" id="Image8" alt="" border="0" style="width:105px;height:45px;"></a></div>
  149. <div id="wb_Image9" style="margin:0;padding:0;position:absolute;left:354px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:9;">
  150. <a href="./nagroda1.php"><img src="images/godzrestocku.png" id="Image9" alt="" border="0" style="width:154px;height:240px;"></a></div>
  151. <div id="wb_Image10" style="margin:0;padding:0;position:absolute;left:552px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:10;">
  152. <img src="images/javelin30.png" id="Image10" alt="" border="0" style="width:154px;height:240px;"></div>
  153. <div id="wb_Image11" style="margin:0;padding:0;position:absolute;left:750px;top:326px;width:154px;heigh
    t:240px;text-align:left;z-index:11;">
  154. <img src="images/pktx2.png" id="Image11" alt="" border="0" style="width:154px;height:240px;"></div>
  155. <div id="wb_Image12" style="margin:0;padding:0;position:absolute;left:354px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:12;">
  156. <img src="images/premiumnagrodaeu.png" id="Image12" alt="" border="0" style="width:154px;height:240px;"></div>
  157. <div id="wb_Image13" style="margin:0;padding:0;position:absolute;left:552px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:13;">
  158. <img src="images/premka3.png" id="Image13" alt="" border="0" style="width:154px;height:240px;"></div>
  159. <div id="wb_Image14" style="margin:0;padding:0;position:absolute;left:751px;top:602px;width:154px;heigh
    t:240px;text-align:left;z-index:14;">
  160. <img src="images/losowygift.png" id="Image14" alt="" border="0" style="width:154px;height:240px;"></div>
  161. <div id="wb_Shape2" style="margin:0;padding:0;position:absolute;left:413px;top:234px;width:453px;heigh
    t:52px;text-align:center;z-index:15;">
  162. <img src="images/img0016.png" id="Shape2" alt="" title="" style="border-width:0;width:453px;height:52px"></div>
  163. <div id="Html1" style="position:absolute;left:593px;top:459px;width:222px;height:252px;z-index:16">
  164.  
  165. <div id="brak1" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  166. <?php echo $error_message1;?></div>
  167.  
  168. <div id="brak2" style="position:absolute;left:40px;top:90px;width:130px;height:29px;z-index:16">
  169. <?php echo $error_message2;?></div>
  170.  
  171. <div id="brak3" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  172. <?php echo $error_message3;?></div>
  173.  
  174. <div id="brak4" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  175. <?php echo $error_message4;?></div>
  176.  
  177. <div id="brak5" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  178. <?php echo $error_message5;?></div>
  179.  
  180. <div id="brak6" style="position:absolute;left:-200px;top:76px;width:119px;height:29px;z-index:16">
  181. <?php echo $error_message6;?></div>
  182. </div>
  183. </div>
  184. </body>
  185. </html>
kadlub
poczytaj trochę na temat php bo tak będziemy pisać i pisać

usuń wszędzie te else

kiepski96
No na początku tak miałem bez else,ale potem mi coś stuknęło smile.gif

THX , all działa
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.