Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Notice przy odpalaniu strony
szokmen
post
Post #1





Grupa: Zarejestrowani
Postów: 30
Pomógł: 0
Dołączył: 19.05.2010

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


Witam,
mam taki kawałek kodu jak poniżej i jest jeden malutki problem jak wpisuje w przeglądarce adres strony to wszystko się wyświetla tak jak trzeba wszystko działa tylko wyskakuje mi tez taki niechciany notice:
Notice: Undefined index: wybor in G:\wamp\www\formularz.php on line 33
i nie bardzo wiem o co chodzi.

  1. echo '<div id="h0">';
  2. echo '<form action= "formularz.php" method="get">';
  3. echo '<input type ="hidden" name="wybor" value="szukaj">';
  4. echo '<input type= "text" name="napis">';
  5. echo '<input type= "submit" value="Szukaj imie">';
  6. echo '</form>';
  7. echo '</div>';
  8.  
  9. echo '<div id="h3">';
  10. echo '<form action= "formularz.php" method="get">';
  11. echo '<input type ="hidden" name="wybor" value="DEL">';
  12. echo '<input type= "hidden" name="id">';
  13. echo '</form>';
  14. echo '</div>';
  15.  
  16. if(isset($_POST["wybor"])== 'dodaj')
  17. {
  18. $imie1=$_POST['imie'];
  19. $nazwisko1=$_POST['nazwisko'];
  20. $nazwa1=$_POST['nazwa_firmy'];
  21. $telefon1=$_POST['telefon'];
  22.  
  23.  
  24. if($imie1 and $nazwisko1 and $nazwa1 and $telefon1)
  25. {
  26.  
  27. $ins =mysql_query("insert into klienci set imie='$imie1', nazwisko='$nazwisko1', nazwa_firmy='$nazwa1',telefon='$telefon1'");
  28. if($ins) echo "Rekord został dodany poprawnie";
  29. else echo "Błąd nie udało się dodać nowego rekordu";
  30. }
  31. }
  32.  
  33. else if ($_GET["wybor"] == 'DEL')
  34. {
  35. $zapytanie3="DELETE from Klienci where id_klienta=$_GET[id];";
  36. $del = mysql_query($zapytanie3);
  37. if($del)
  38. {
  39. echo '<h5>rekord usuniety</h5>';
  40.  
  41. }
  42. else
  43. {
  44. echo '<h5>blad</h5>';
  45. mysql_query($del) or die('BŁĄD:'.mysql_error());
  46. }
  47. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
szokmen
post
Post #2





Grupa: Zarejestrowani
Postów: 30
Pomógł: 0
Dołączył: 19.05.2010

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


Poniżej znajduje się cały kod umieszczam go, ponieważ jak daje isset w:
  1. else if ($_GET["wybor"] == 'DEL')
to wtedy jak kliknę "Szukaj imie" z moja stroną dzieją się takie rzeczy

Notice: Undefined index: id in G:\wamp\www\formularz.php on line 72
blad

BŁĄD:Query was empty
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
  4. <title>Projekt bazy danych</title>
  5. <link rel="stylesheet" type="text/css" href="styl.css" />
  6. </head>
  7. <body>
  8. <div id="h2">
  9. <form action="formularz.php" method="post">
  10. <p align="right">
  11. <input type ="hidden" name="wybor" value="dodaj">
  12. <table>
  13. id klienta:<input type ="text" name="id"><br />
  14. imie:<input type ="text" name="imie"><br />
  15. nazwisko:<input type ="text" name="nazwisko"><br />
  16. nazwa firmy:<input type ="text" name="nazwa_firmy"><br />
  17. telefon:<input type ="text" name="telefon"><br />
  18. <input type ="submit" value="dodaj">
  19. </table>
  20. </p>
  21. </form>
  22. </div>
  23.  
  24.  
  25. <?php
  26. ini_set('display_errors','1');
  27.  
  28. mysql_connect("localhost", "szymon", "28360405") or die ("Nie można połączyć się z bazą");
  29. mysql_select_db ("firma") or die ("Nie można połączyć się z bazą firma");
  30. echo '<div id="h0">';
  31. echo '<form action= "formularz.php" method="get">';
  32. echo '<input type ="hidden" name="wybor" value="szukaj">';
  33. echo '<input type= "text" name="napis">';
  34. echo '<input type= "submit" value="Szukaj imie">';
  35. echo '</form>';
  36. echo '</div>';
  37.  
  38. echo '<div id="h3">';
  39. echo '<form action= "formularz.php" method="get">';
  40. echo '<input type ="hidden" name="wybor" value="DEL">';
  41. echo '<input type ="hidden" name="wybor" value="edit">';
  42. echo '<input type= "hidden" name="id">';
  43. echo '</form>';
  44. echo '</div>';
  45.  
  46. echo '<form action= "formularz.php" method="get">';
  47. echo '<input type ="hidden" name="wybor" value="edit">';
  48. echo '<input type= "hidden" name="id">';
  49. echo '</form>';
  50.  
  51.  
  52. if(isset($_POST["wybor"])== 'dodaj')
  53. {
  54. $imie1=$_POST['imie'];
  55. $nazwisko1=$_POST['nazwisko'];
  56. $nazwa1=$_POST['nazwa_firmy'];
  57. $telefon1=$_POST['telefon'];
  58.  
  59.  
  60. if($imie1 and $nazwisko1 and $nazwa1 and $telefon1)
  61. {
  62.  
  63. $ins =mysql_query("insert into klienci set imie='$imie1', nazwisko='$nazwisko1', nazwa_firmy='$nazwa1',telefon='$telefon1'");
  64. if($ins) echo "Rekord został dodany poprawnie";
  65. else echo "Błąd nie udało się dodać nowego rekordu";
  66. }
  67. }
  68.  
  69. else if (isset($_GET["wybor"]) == 'DEL')
  70. {
  71. $zapytanie3="DELETE from Klienci where id_klienta=$_GET[id];";
  72. $del = mysql_query($zapytanie3);
  73. if($del)
  74. {
  75. echo '<h5>rekord usuniety</h5>';
  76.  
  77. }
  78. else
  79. {
  80. echo '<h5>blad</h5>';
  81. mysql_query($del) or die('BŁĄD:'.mysql_error());
  82. }
  83. }
  84.  
  85. else if ($_GET["wybor"] == 'edit')
  86. {
  87. echo '<form action="formularz.php" method="post">';
  88. echo '<p align="right">';
  89. echo '<table>';
  90. echo 'id klienta:<input type ="text" name="id"><br />';
  91. echo 'imie:<input type ="text" name="imie"><br />';
  92. echo 'nazwisko:<input type ="text" name="nazwisko"><br />';
  93. echo 'nazwa firmy:<input type ="text" name="nazwa_firmy"><br />';
  94. echo 'telefon:<input type ="text" name="telefon"><br />';
  95. echo '<input type ="submit" value="zmień">';
  96. echo '</table>';
  97. echo '</p>';
  98. echo '</form>';
  99. }
  100.  
  101.  
  102.  
  103. else if (isset($_GET["napis"]))
  104. {
  105.  
  106. $zapytanie2="SELECT *from klienci where imie='$_GET[napis]'";
  107. $wyk2=mysql_query($zapytanie2);
  108.  
  109. if ($_GET["wybor"]== 'szukaj')
  110. {
  111. if(mysql_num_rows($wyk2) > 0)
  112. {
  113.  
  114. echo ("<h1><b>Znaleziono</b></h1>");
  115. //echo '<div id="h6">';
  116. echo "<table cellpading=5 border=2>";
  117. echo "<tr>";
  118. echo "<td><b>Id_klienta</td></b>";
  119. echo "<td><b>Imie</td></b>";
  120. echo "<td><b>Nazwisko</td></b>";
  121. echo "<td><b>Nazwa firmy</td></b>";
  122. echo "<td><b>Telefon</td></b>";
  123. echo "</tr>\n";
  124. }
  125. else echo ("<h1><b>Nie ma</b></h1>");
  126.  
  127. echo '<br/>';
  128. while($rek=mysql_fetch_array($wyk2))
  129. {
  130. $id2 =$rek[0];
  131. $imie2=$rek[1];
  132. $nazwisko2=$rek[2];
  133. $nazwa_firmy2=$rek[3];
  134. $telefon2=$rek[4];
  135.  
  136. echo "<tr>";
  137. echo "<td><b>$id2</td></b>";
  138. echo "<td><b>$imie2</td></b>";
  139. echo "<td><b>$nazwisko2</td></b>";
  140. echo "<td><b>$nazwa_firmy2</td></b>";
  141. echo "<td><b>$telefon2</td></b>";
  142. echo "</tr>\n";
  143. //echo '</div>';
  144. }
  145. echo "</table>";
  146.  
  147. echo '<a href ="formularz.php"> Powrot do formularza</a>';
  148.  
  149. }
  150. }
  151.  
  152. $zapytanie1 = "SELECT *from klienci";
  153. $wyk1=mysql_query($zapytanie1);
  154.  
  155. //echo '<div id="h4">';
  156. echo "<table cellpading=5 border=2>";
  157. echo "<tr>";
  158. echo "<td><b>Id_klienta</td></b>";
  159. echo "<td><b>Imie</td></b>";
  160. echo "<td><b>Nazwisko</td></b>";
  161. echo "<td><b>Nazwa firmy</td></b>";
  162. echo "<td><b>Telefon</td></b>";
  163. echo "</tr>\n";
  164.  
  165. while($rekord=mysql_fetch_array($wyk1))
  166. {
  167. $id =$rekord[0];
  168. $imie=$rekord[1];
  169. $nazwisko=$rekord[2];
  170. $nazwa_firmy=$rekord[3];
  171. $telefon=$rekord[4];
  172.  
  173. echo "<tr>";
  174. echo "<td><b>$id</td></b>";
  175. echo "<td><b>$imie</td></b>";
  176. echo "<td><b>$nazwisko</td></b>";
  177. echo "<td><b>$nazwa_firmy</td></b>";
  178. echo "<td><b>$telefon</td></b>";
  179. echo "<td><a href = \"formularz.php?wybor=DEL&Id=$id\">kasuj</a></td>";
  180. echo "<td><a href = \"formularz.php?wybor=edit&Id=$id\">edytuj</a></td>";
  181. echo "</tr>\n";
  182. echo '</div>';
  183. }
  184. echo "</table>";
  185. //echo '</div>';
  186. ?>
  187.  
  188. </body>
  189. </html>

Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.12.2025 - 15:09