Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> automatyczne wyciąganie danych, Undefined offset
Lonas
post
Post #1





Grupa: Zarejestrowani
Postów: 576
Pomógł: 14
Dołączył: 9.11.2005

Ostrzeżenie: (20%)
X----


Mam male pytanko, co powinienem zmienić żeby automatycznie wyciągane byly dane 1 kontrahenta z selecta ( bez klikniecia w niego ), mialem tutaj problem z form action wiec dane zapisalem do sesji z tym ze na poczatku nie jest jeszcze wybrany kontrahent i pokazuje mi bład "Undefined offset:" tam gdzie wyciaga sie nazwa z bazy danych

  1. $db = mysql_pconnect("localhost", "root");
  2. mysql_select_db("faktury"); 
  3. if (!$db) {     
  4.     print "wystąpił błąd w połączeniu";     
  5.     exit;  
  6. }  
  7. function ShowSel() {
  8.     $result = mysql_query("select nazwa from kontrahenci"); 
  9.     while($dane = mysql_fetch_array($result)){
  10.          echo '<option value="'.$dane[0].'">'.$dane[0].'</option>';
  11.  
  12.  }    
  13.  
  14. }
  15.  
  16.  
  17.  
  18.  
  19.  
  20. if(isset($_POST["hid"]) && !empty($_POST["hid"]) && $_POST["hid"]!="--") {
  21.     $res = mysql_query("select ulica,nrdomu,miasto,nazwa from kontrahenci where 
  22.  
  23. nazwa='".$_POST["s"]."'");
  24.     $dane = mysql_fetch_row($res);
  25. } else {
  26.     $dane = array_fill(0,3," ");
  27.  
  28. }
  29. $_SESSION['ulica'] = $dane[0];
  30. $_SESSION['nrdomu'] = $dane[1];
  31. $_SESSION['miasto'] = $dane[2];
  32. $_SESSION['nazwa'] = $dane[3]; 
  33.  
  34. ?>
  35.  
  36. <form action="test.php " method="post">
  37. <select id="s" name="s" 
  38.  
  39. onchange="document.getElementById('hid').value='submit';this.form.submit()">
  40. <option value="--">--</option>
  41. <?php ShowSel(); ?>
  42. </select><br /><br />
  43.  
  44.  
  45. <br><br>
  46. <input id="hid" name="hid" type="hidden" value="$_POST["s"]" />
  47. nazwa: <input type="text" id="t1" name="t1" value="<?php echo $dane[3]; ?>" /><br />
  48. adres: <input type="text" id="t1" name="t1" value="<?php echo $dane[0]; ?>" /><br />
  49. nip: <input type="text" id="t2" name="t2" value="<?php echo $dane[1]; ?>" /><br />
  50. miasto: <input type="text" id="t3" name="t3" value="<?php echo $dane[2]; ?>" />
  51. </form>
  52. <a href= show2.php> dalej </a>


Ten post edytował L.Pociask 29.11.2005, 16:35:12
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Co ja się z tobą mam (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Jak nie to forum, to łączysz tematy. Jak nie bbcode, to zły temat (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

"Pytanie - mala poprawka" taki tytuł nic nie wnosi do tematu. Zamykam. Podaj mi na PW nowy tytul a odblokuje. Przeciez na tytuł moze skladac sie chociazby komunikat o bledzie i juz bedzie git.

edit: otwieram

  1. <?php
  2.  
  3. $dane = array_fill(0,3," ");
  4.  
  5. ?>
manual sie klania. Wypelniasz tablice $dane tylko trzema elementami, a pozniej odwolujesz sie do czwartego, którego nie ma, wiec stąd ten warning

A jesli chcesz na poczatku wypelniac inputy pierwszym lepszym kontrahentem to:
  1. <?php
  2.  
  3. if(isset($_POST["hid"]) && !empty($_POST["hid"]) && $_POST["hid"]!="--") 
  4. $res = mysql_query("select ulica,nrdomu,miasto,nazwa from kontrahenci where 
  5. nazwa='".$_POST["s"]."'");
  6. else
  7.  $res = mysql_query("select ulica,nrdomu,miasto,nazwa from kontrahenci limit 1");
  8. $dane = mysql_fetch_row($res);
  9. //.....
  10.  
  11. ?>
Go to the top of the page
+Quote Post
Lonas
post
Post #3





Grupa: Zarejestrowani
Postów: 576
Pomógł: 14
Dołączył: 9.11.2005

Ostrzeżenie: (20%)
X----


No tak, teraz nie wywala błedu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Pięknie dziekuje i do usłyszenia hehe (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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: 23.08.2025 - 08:51