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%)
-----


nie ma form2.php, to jest plik form2.php, jedyny, nie ma wiecej, i wszytsko jest w jednym pliku, zduplikuje go jeszcze raz.

  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.  
  14. <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  15. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  16. <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
  17.  
  18. <script>
  19. $( ".selector" ).datepicker({ dateFormat: 'yy-mm-dd' });
  20. $(function() {
  21.  
  22. var dates = $( "#from, #to" ).datepicker({
  23. defaultDate: "+1w",
  24. changeMonth: true,
  25. numberOfMonths: 3,
  26. onSelect: function( selectedDate ) {
  27. var option = this.id == "from" ? "minDate" : "maxDate",
  28. instance = $( this ).data( "datepicker" );
  29. date = $.datepicker.parseDate(
  30. instance.settings.dateFormat ||
  31. $.datepicker._defaults.dateFormat,
  32. selectedDate, instance.settings );
  33. dates.not( this ).datepicker( "option", option, date );
  34.  
  35. }
  36. });
  37. });
  38.  
  39. </script>
  40. </head>
  41. <body>
  42. <div id="box">
  43. <div id="logo">
  44. <h1>Formularz rozliczeń</h1>
  45. <h2>blablablabla</h2>
  46.  
  47. </div>
  48. <br />
  49. <div id="form">
  50. <form action="form2.php" method="post">
  51. <ul>
  52. <li>
  53. <label class="opis">Technik: </label>
  54. <?php
  55. $adres = 'form2.php?technik=';
  56. ?>
  57. <select onchange="self.location.href = this.value" name="technik">
  58. <option value="1" ></option>
  59. <option value="<?php echo $adres.'technik1&';?>" >Technik 1</option>
  60. <option value="<?php echo $adres.'technik2&';?>" >Technik 2</option>
  61. <option value="<?php echo $adres.'technik3&';?>" >Technim3</option>
  62. </select>
  63. </li><li>
  64. <label class="opis">Od: </label>
  65. <input type="text" id="from" name="from"/>
  66. </li><li>
  67. <label class="opis">Do: </label>
  68. <input type="text" id="to" name="to"/>
  69. </li>
  70. </ul>
  71. <br /><br />
  72. <ul><li>
  73. <button type="submit">Szukaj</button>
  74. </li><li>
  75. <button type="reset">Wyczyść</button>
  76. </li></ul>
  77. </form>
  78. <br /><br /><br />
  79. <hr />
  80. <form action="form2.php" method="post">
  81. <ul>
  82. <li>
  83. <label class="opis">Numer: </label>
  84. <input name="numer" type="text" maxlength="255" value=""/>
  85. </li><li>
  86. <label class="opis">Data: </label>
  87. <input type="text" size="7" name="data" value="<? echo date("d-m-Y");?>">
  88. </li><li>
  89. <label class="opis">Typ: </label>
  90. <select name="typ">
  91. <option value="1" >Gwarancja</option>
  92. <option value="2" >Odpłatne</option>
  93. <option value="3" >Inne</option>
  94. </select>
  95. </li><li>
  96. <label class="opis">Robocizna: </label>
  97. <input name="robocizna" type="text" size="5" maxlength="5" value=""/>
  98. </li><li>
  99. <label class="opis">Materiał: </label>
  100. <input name="material" type="text" size="5" maxlength="5" value=""/>
  101. </li><li>
  102. <label class="opis">Dojazd: </label>
  103. <input name="dojazd" type="text" size="5" maxlength="5" value=""/>
  104. </li><li>
  105. <label class="opis">Inne: </label>
  106. <input name="inne" type="text" size="5" maxlength="5" value=""/>
  107. </li><li>
  108. <label class="opis">Procent: </label>
  109. <input name="procent" type="text" size="5" maxlength="5" value="45"/> %
  110. </li><li>
  111. <label class="opis">Opis: </label>
  112. <input name="opis" type="text" size="25" maxlength="255" value=""/>
  113. </li></ul>
  114. <br /><br />
  115. <ul><li>
  116.  
  117. <input type="submit" value="Wyślij"/>
  118. </li><li>
  119. <button type="reset">Wyczyść</button>
  120. </li></ul>
  121. </form></div>
  122. <?
  123.  
  124. /*$technik = $_POST['technik']; */
  125. $numer = $_POST['numer'];
  126. $data = $_POST['data'];
  127. $typ = $_POST['typ'];
  128. $robocizna = $_POST['robocizna'];
  129. $material = $_POST['matrial'];
  130. $dojazd = $_POST['dojazd'];
  131. $inne = $_POST['inne'];
  132. $procent = $_POST['procent'];
  133. $opis = $_POST['opis'];
  134.  
  135. if($numer and $data and $typ and $robocizna and $material and $dojazd and $inne and $procent and $opis) {
  136.  
  137.  
  138. $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'");
  139.  
  140. if($ins) echo "Rekord został dodany poprawnie";
  141. else echo "Błąd nie udało się dodać nowego rekordu";
  142.  
  143.  
  144. }
  145. ?>
  146. <br /><br /><br /><br />
  147. <hr />
  148. <table>
  149. <tr class="glowne">
  150. <td>Numer:</td>
  151. <td>Data:</td>
  152. <td>Typ:</td>
  153. <td>Robocizna:</td>
  154. <td>Materiał:</td>
  155. <td>Dojazd:</td>
  156. <td>Inne:</td>
  157. <td>Procent:</td>
  158. <td>Opis:</td>
  159. </tr>
  160.  
  161. <?php
  162.  
  163. $technik = trim($_GET['technik']);
  164. $wynik = mysql_query("SELECT * FROM rozliczenie WHERE technik='$technik'")
  165. or die('Błąd zapytania');
  166. if(mysql_num_rows($wynik) > 0) {
  167. echo "<tr> ";
  168. while($r = mysql_fetch_assoc($wynik)) {
  169.  
  170. $counter++;
  171. if ( ($r['numer'] && $r['data'] && $r['typ']) == null) {
  172. $list="list3";
  173. } else {
  174. if ( $counter % 2 == 0) {
  175. $list = "list1";
  176. } else {
  177. $list = "list2";
  178. }
  179. }
  180.  
  181. echo "<tr class=\"$list\">";
  182. echo "<td width=\"15px\">".$r['numer']."</td>";
  183. echo "<td width=\"80px\">".$r['data']."</td>";
  184. echo "<td width=\"90px\">".$r['typ']."</td>";
  185. echo "<td width=\"80px\">".$r['robocizna']."</td>";
  186. echo "<td width=\"150px\">".$r['material']."</td>";
  187. echo "<td class=\"nazwisko\">".$r['dojazd']."</td>";
  188. echo "<td width=\"60px\">".$r['inne']."</td>";
  189. echo "<td width=\"150px\">".$r['procent']."</td>";
  190. echo "<td width=\"50px\">".$r['opis']."</td></tr>";
  191. }
  192. echo "</table>";
  193. }
  194. ?>
  195.  
  196. </div>
  197. </body>
  198. </html>


Ten post edytował bercow 12.02.2011, 13:20:58
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 6.10.2025 - 02:45