Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MySQL]Wysyłanie formularza, link w polu select
bercow
post
Post #1





Grupa: Zarejestrowani
Postów: 156
Pomógł: 11
Dołączył: 25.12.2005

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


Witam.

Mamy sobie kod jak nizej, w nim dwa form. jeden bedzie do wyciagania danych, drugi do dodawania. Narazie zajmuje sie tym drugim, ale nie wiedziec czemu nie dziala mi zbytnio wysylanie, nie wyswietla zadnego bledu. Dziala pobieranie danych z bazy. Linie 161 - 181

Druga sprawa, mam pole select, i chcial bym, aby po kliknieciu na jakas pozycje, przechodzilo na dana strone, dokladniej form2.php?technik=Technik 1&, linie 44-49

  1. <?
  2. require "connection.php";
  3. connection();
  4. ?>
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  7. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
  9. <head>
  10. <title>Eldom Bis</title>
  11. <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
  12. <link rel="stylesheet" type="text/css" href="style2.css" />
  13. <link rel="stylesheet" type="text/css" href="calendar.css" />
  14. <link rel="stylesheet" href="jquery.ui.all.css">
  15.  
  16. <script src="js/jquery-1.4.4.js"></script>
  17. <script src="js/jquery.ui.core.js"></script>
  18. <script src="js/jquery.ui.widget.js"></script>
  19. <script src="js/jquery.ui.datepicker.js"></script>
  20.  
  21. <script type="text/javascript" src="view.js"></script>
  22. <script type="text/javascript" src="calendar.js"></script>
  23.  
  24. <script>
  25. $(function() {
  26. $( "#datepicker" ).datepicker();
  27. });
  28. </script>
  29. </head>
  30. <body>
  31. <div id="box">
  32. <div id="logo">
  33. <div class="demo">
  34.  
  35. <p>Date: <input type="text" id="datepicker"></p>
  36. </div>
  37. </div>
  38. <br />
  39. <div id="form">
  40. <form action="form2.php" method="post">
  41. <ul>
  42. <li>
  43. <label class="opis">Technik: </label>
  44. <select class="element select medium" id="element_1" name="element_1">
  45. <option value="1" ></option>
  46. <option value="2" ><a href="www.wp.pl">Technik 1</a></option>
  47. <a href="www.wp.pl"><option value="3" >Technik 2</option></a>
  48. <option value="4" >Technim3</option>
  49. </select>
  50. </li><li>
  51. <label class="opis">Od: </label>
  52. <span>
  53. <input size="2" maxlength="2" value="" type="text"> /
  54. <label >MM</label>
  55. </span>
  56. <span>
  57. <input size="2" maxlength="2" value="" type="text"> /
  58. <label >DD</label>
  59. </span>
  60. <span>
  61. <input size="4" maxlength="4" value="" type="text">
  62. <label >YYYY</label>
  63. </span>
  64.  
  65. <span>
  66. <img id="cal_img_2" class="datepicker" src="calendar.gif" alt="Pick a date.">
  67. </span>
  68. <script type="text/javascript">
  69. Calendar.setup({
  70. inputField : "element_2_3",
  71. baseField : "element_2",
  72. displayArea : "calendar_2",
  73. button : "cal_img_2",
  74. ifFormat : "%B %e, %Y",
  75. onSelect : selectDate
  76. });
  77. </script>
  78. </li><li>
  79. <label class="opis">Od: </label>
  80. <span>
  81. <input size="2" maxlength="2" value="" type="text"> /
  82. <label >MM</label>
  83. </span>
  84. <span>
  85. <input size="2" maxlength="2" value="" type="text"> /
  86. <label >DD</label>
  87. </span>
  88. <span>
  89. <input size="4" maxlength="4" value="" type="text">
  90. <label >YYYY</label>
  91. </span>
  92.  
  93. <span>
  94. <img id="cal_img_2" class="datepicker" src="calendar.gif" alt="Pick a date.">
  95. </span>
  96. <script type="text/javascript">
  97. Calendar.setup({
  98. inputField : "element_2_3",
  99. baseField : "element_2",
  100. displayArea : "calendar_2",
  101. button : "cal_img_2",
  102. ifFormat : "%B %e, %Y",
  103. onSelect : selectDate
  104. });
  105. </script>
  106. </li>
  107. </ul>
  108. <br /><br />
  109. <ul><li>
  110. <button type="submit">Szukaj</button>
  111. </li><li>
  112. <button type="reset">Wyczyść</button>
  113. </li></ul>
  114. </form>
  115. <br /><br /><br />
  116. <hr />
  117. <form action="form2.php" method="post">
  118. <ul>
  119. <li>
  120. <label class="opis">Numer: </label>
  121. <input name="numer" type="text" maxlength="255" value=""/>
  122. </li><li>
  123. <label class="opis">Data: </label>
  124. <input type="text" size="7" name="data" value="<? echo date("d-m-Y");?>">
  125. </li><li>
  126. <label class="opis">Typ: </label>
  127. <select name="typ">
  128. <option value="1" >Gwarancja</option>
  129. <option value="2" >Odpłatne</option>
  130. <option value="3" >Inne</option>
  131. </select>
  132. </li><li>
  133. <label class="opis">Robocizna: </label>
  134. <input name="robocizna" type="text" size="5" maxlength="5" value=""/>
  135. </li><li>
  136. <label class="opis">Materiał: </label>
  137. <input name="material" type="text" size="5" maxlength="5" value=""/>
  138. </li><li>
  139. <label class="opis">Dojazd: </label>
  140. <input name="dojazd" type="text" size="5" maxlength="5" value=""/>
  141. </li><li>
  142. <label class="opis">Inne: </label>
  143. <input name="inne" type="text" size="5" maxlength="5" value=""/>
  144. </li><li>
  145. <label class="opis">Procent: </label>
  146. <input name="procent" type="text" size="5" maxlength="5" value=""/>
  147. </li><li>
  148. <label class="opis">Opis: </label>
  149. <input name="opis" type="text" size="25" maxlength="255" value=""/>
  150. </li></ul>
  151. <br /><br />
  152. <ul><li>
  153.  
  154. <input type="submit" value="Wyślij"/>
  155. </li><li>
  156. <button type="reset">Wyczyść</button>
  157. </li></ul>
  158. </form>
  159. <?
  160.  
  161. /*$technik = $_POST['technik']; */
  162. $numer = $_POST['numer'];
  163. $data = $_POST['data'];
  164. $typ = $_POST['typ'];
  165. $robocizna = $_POST['robocizna'];
  166. $material = $_POST['matrial'];
  167. $dojazd = $_POST['dojazd'];
  168. $inne = $_POST['inne'];
  169. $procent = $_POST['procent'];
  170. $opis = $_POST['opis'];
  171.  
  172. if($numer and $data and $typ and $robocizna and $material and $dojazd and $inne and $procent and $opis) {
  173.  
  174.  
  175. $ins = @mysql_query("INSERT INTO test SET numer='$numer', data='$data', typ='$typ', robocizna='$robocizna', material='$material', dojazd='$dojazd', inne='$inne', procent='$procent', opis='$opis'");
  176.  
  177. if($ins) echo "Rekord został dodany poprawnie";
  178. else echo "Błąd nie udało się dodać nowego rekordu";
  179.  
  180.  
  181. }
  182. ?>
  183. <br /><br /><br /><br />
  184. <hr />
  185. <table>
  186. <tr class="glowne">
  187. <td>Numer:</td>
  188. <td>Data:</td>
  189. <td>Typ:</td>
  190. <td>Robocizna:</td>
  191. <td>Materiał:</td>
  192. <td>Dojazd:</td>
  193. <td>Inne:</td>
  194. <td>Procent:</td>
  195. <td>Opis:</td>
  196. </tr>
  197.  
  198. <?php
  199.  
  200. $wynik = mysql_query("SELECT * FROM rozliczenie")
  201. or die('Błąd zapytania');
  202. if(mysql_num_rows($wynik) > 0) {
  203. echo "<tr> ";
  204. while($r = mysql_fetch_assoc($wynik)) {
  205.  
  206. $counter++;
  207. if ( ($r['numer'] && $r['data'] && $r['typ']) == null) {
  208. $list="list3";
  209. } else {
  210. if ( $counter % 2 == 0) {
  211. $list = "list1";
  212. } else {
  213. $list = "list2";
  214. }
  215. }
  216.  
  217. echo "<tr class=\"$list\">";
  218. echo "<td width=\"15px\">".$r['numer']."</td>";
  219. echo "<td width=\"80px\">".$r['data']."</td>";
  220. echo "<td width=\"90px\">".$r['typ']."</td>";
  221. echo "<td width=\"80px\">".$r['robocizna']."</td>";
  222. echo "<td width=\"150px\">".$r['material']."</td>";
  223. echo "<td class=\"nazwisko\">".$r['dojazd']."</td>";
  224. echo "<td width=\"60px\">".$r['inne']."</td>";
  225. echo "<td width=\"150px\">".$r['procent']."</td>";
  226. echo "<td width=\"50px\">".$r['opis']."</td></tr>";
  227. }
  228. echo "</table>";
  229. }
  230. ?>
  231. </div>
  232. </div>
  233. </body>
  234. </html>


  1. --
  2. -- Struktura tabeli dla `test`
  3. --
  4.  
  5. CREATE TABLE IF NOT EXISTS `test` (
  6. `numer` text NOT NULL,
  7. `data` text NOT NULL,
  8. `typ` text NOT NULL,
  9. `robocizna` text NOT NULL,
  10. `material` text NOT NULL,
  11. `dojazd` text NOT NULL,
  12. `inne` text NOT NULL,
  13. `procent` text NOT NULL,
  14. `opis` text NOT NULL
  15. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  16.  
  17. --
  18. -- Zrzut danych tabeli `test`
  19. --
  20.  
  21. INSERT INTO `test` (`numer`, `data`, `typ`, `robocizna`, `material`, `dojazd`, `inne`, `procent`, `opis`) VALUES
  22. (0, 0, 0, 0, 0, 0, 0, 0, 0);


Ten post edytował bercow 12.02.2011, 10:35:00
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
bercow
post
Post #2





Grupa: Zarejestrowani
Postów: 156
Pomógł: 11
Dołączył: 25.12.2005

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


Faktycznie mam w pierwszym form metode post, a wiec zmienimy troche koncepcje, pierwszy form, nie bedzie juz form z post, beda to trzy pola, i kazde z nich bede sie starał trzymac w adresie, po wybraniu technika dostajemy form2.php?technik=technik1&, po wpisaniu daty, i kliknieciu przycisku, szukaj adres sie zmieni na form2.php?technik=technik1od=0000-00-01&do=0000-00-02&, w pierwszym wypadku, mamy wyswietlone wszytskie rekordy, w drugim chcial bym, juz wybrac dokladny przedzial datowy. Wtedy pobieral bym go z get. Ale on znika tzn. raz, ze daty nie wchodza do zmiennej, a dwa on znika, mimo iz jest wyswietlany, to nie dodaje sie w drugim form. Wartosci na 1 2 3 niechce zmieniac, bo wtedy w bazie bym musial dodac druga tabele, a lista technikow nie zmienia sie zbyt czesto, i latwiej dodac jedna linjke w kodzie juz dodac, niz nowa tebele.

  1. <form action="form2.php" method="get">
  2. <ul>
  3. <li>
  4. <label class="opis">Technik: </label>
  5. <?php
  6. $adres = 'form2.php?technik=';
  7. ?>
  8. <select onchange="self.location.href = this.value" name="technik">
  9. <option value="1" ></option>
  10. <option value="<?php echo $adres.'technik1&amp;';?>" >Technik 1</option>
  11. <option value="<?php echo $adres.'technik2&amp;';?>" >Technik 2</option>
  12. <option value="<?php echo $adres.'technik3&amp;';?>" >Technik 3</option>
  13. </select>
  14. </li><li>
  15. <label class="opis">Od: </label>
  16. <input type="text" id="from" name="od"/>
  17. </li><li>
  18. <label class="opis">Do: </label>
  19. <input type="text" id="to" name="do"/>
  20. </li>
  21. </ul>
  22. <br /><br />
  23. <ul><li></form>
  24. <?php
  25. $od = $_GET['od'];
  26. $do = $_GET['do'];
  27. $technik = trim($_GET['technik']);
  28. echo "$od"."$do";
  29.  
  30.  
  31. echo '<a href="';?><?php echo "$adres"."$technik".'&amp;'.'od='."$od".'&amp;'.'do='."$do".'&amp;';?>" onclick="popUp(this.href, 'scrolling', 452, 452); return false;" rel="external">
  32. <input type="submit" name="button" value="Szukaj" /></a>
  33.  
  34. </li><li>
  35. <button type="reset">Wyczyść</button>
  36. </li></ul>
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 6.10.2025 - 08:21