Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z przesyłaniem danych
Forum PHP.pl > Forum > Przedszkole
Gość
Witam exclamation.gif

Mam sobie skrypt w js odpowiedzialny za dodawnie nowego wiersza w forumlarzu:
  1. <script type="text/javascript">
  2. var i = 1;
  3. function dodaj(id)
  4. {
  5. var Div = document.getElementById(id);
  6. var numer = document.createElement("input");
  7. var imie = document.createElement("input");
  8. var pojazd = document.createElement("input");
  9. var etrt = document.createElement("input");
  10. var et = document.createElement("input");
  11. var br = document.createElement("br");
  12.  
  13. var divn = document.createElement("span");
  14. divn.setAttribute("class","style4");
  15. divn.innerHTML=i+'. Numer startowy: ';
  16.  
  17. var divw = document.createElement("span");
  18. divw.setAttribute("class","style4");
  19. divw.innerHTML=' Nazwisko i imię: ';
  20. Div.appendChild(divn);
  21.  
  22. var divy = document.createElement("span");
  23. divy.setAttribute("class","style4");
  24. divy.innerHTML=' Pojazd: ';
  25. Div.appendChild(divy);
  26.  
  27. var divz = document.createElement("span");
  28. divz.setAttribute("class","style4");
  29. divz.innerHTML=' ET+RT: ';
  30. Div.appendChild(divz);
  31.  
  32. var divr = document.createElement("span");
  33. divr.setAttribute("class","style4");
  34. divr.innerHTML=' ET: ';
  35. Div.appendChild(divr);
  36.  
  37. numer.setAttribute("name","numer["+i+"]");
  38. numer.setAttribute("type","text");
  39. numer.setAttribute("size","5");
  40. numer.setAttribute("class","style4");
  41. Div.appendChild(numer);
  42.  
  43. Div.appendChild(divw);
  44. imie.setAttribute("name","imie["+i+"]");
  45. imie.setAttribute("type","text");
  46. imie.setAttribute("size","15");
  47. imie.setAttribute("class","style4");
  48. Div.appendChild(imie);
  49.  
  50. Div.appendChild(divy);
  51. pojazd.setAttribute("name","pojazd["+i+"]");
  52. pojazd.setAttribute("type","text");
  53. pojazd.setAttribute("size","15");
  54. pojazd.setAttribute("class","style4");
  55. Div.appendChild(pojazd);
  56.  
  57. Div.appendChild(divz);
  58. etrt.setAttribute("name","etrt["+i+"]");
  59. etrt.setAttribute("type","text");
  60. etrt.setAttribute("size","15");
  61. etrt.setAttribute("class","style4");
  62. Div.appendChild(etrt);
  63.  
  64. Div.appendChild(divr);
  65. et.setAttribute("name","et["+i+"]");
  66. et.setAttribute("type","text");
  67. et.setAttribute("size","15");
  68. et.setAttribute("class","style4");
  69. Div.appendChild(et);
  70.  
  71.  
  72. Div.appendChild(br);
  73. ++i;
  74. }


A potem mam plik obrabiający dane z formularza i wysyłające dane do bazy danych:

  1. <?
  2.  
  3.  
  4.  
  5. $serwer='localhost';
  6. $user='******';
  7. $pass='******';
  8. $baza='jbs_ip';
  9.  
  10.  
  11. $sql=mysql_connect($serwer,$user,$pass);
  12.  
  13. if (isset($_POST['Send']))
  14. {
  15. $numer=$_POST['numer'];
  16. $imie=$_POST['imie'];
  17. $pojazd=$_POST['pojazd'];
  18. $etrt=$_POST['etrt'];
  19. $et=$_POST['et'];
  20.  
  21.  
  22.  
  23. $insert="INSERT INTO `eleminacje`
  24. (`id` ,
  25.  `numer` ,
  26.  `imie` ,
  27.  `pojazd` ,
  28.  `etrt` ,
  29.  `et` )
  30. VALUES
  31. ('',
  32. '".$numer."',
  33. '".$imie."',
  34. '".$pojazd."',
  35. '".$etrt."',
  36. '".$et."');";
  37.  
  38.  if (!mysql_query($insert))
  39. echo $insert;
  40. print ('Dane zostały przesłane pomyślnie');
  41. }
  42. else
  43. print ('ERROR');
  44.  
  45.  
  46.  
  47.  
  48. ?>


Problem polega na tym że jak przeglądam dane w phpmyadmin to zamiast tego co było w polach formularza widze same słowa Array. Nie wiem w czym tkwi problem. Siedze juz drugi dzien nad tym :/ Ja jednak jestem za tym że jest coś ze skryptem js, cos musi motac z nazwami input'ów albo coś w tym stylu ale z javascriptu jestem kompletnie zielony.
zombie
Nie wiem w jakim celu, ale Twoj JS tworzy tablice. Musisz przerobic JS, albo zamienic kod
  1. <?php
  2. $numer=$_POST['numer'];
  3. $imie=$_POST['imie'];
  4. $pojazd=$_POST['pojazd'];
  5. $etrt=$_POST['etrt'];
  6. $et=$_POST['et'];
  7. ?>

na
  1. <?php
  2. $numer=$_POST['numer'][1];
  3. $imie=$_POST['imie'][1];
  4. $pojazd=$_POST['pojazd'][1];
  5. $etrt=$_POST['etrt'][1];
  6. $et=$_POST['et'][1];
  7. ?>
Gość
No właśnie a czy ktoś z Was pomógłby mi zmienić ten kod js....ale moze najpierw powiem co ma robic.....skrypt sluzy do wpisywania wyników eleminacji pewnych zawodów. Jak to bywa czesto nie wiadomo ilu bedzie zawodników, dlatego tez mozna sobie dodawac pola. Chodzi mi zeby mozna to bylo normalnie wrzucic do bazy.
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.