Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] błąd w koszyku po dodaniu zmiennej
agataperz
post
Post #1





Grupa: Zarejestrowani
Postów: 182
Pomógł: 0
Dołączył: 24.03.2009
Skąd: Hamburg DE

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


Witam,

mam problem - jest sobie skrypt:
  1. function odbierz($txt) {
  2. if (get_magic_quotes_gpc()) $txt = stripslashes($txt);
  3. return str_replace(array('\\',"'"), array('\\\\',"\'"), trim($txt));
  4. }
  5.  
  6.  
  7. $id = odbierz($_REQUEST["id"]);
  8. $sz = isset($_REQUEST["sz"])?number_format($_REQUEST["sz"],0,".",""):"";
  9.  
  10. if ($id<>"") {
  11. if (mysql_connect($sql_serwer, $sql_login, $sql_haslo)
  12. and mysql_select_db($sql_baza)) {
  13. $wynik = mysql_query("SELECT * FROM ehi_produkty WHERE id_produktu='$id'");
  14. }
  15. if ($wynik and mysql_num_rows($wynik)==1) {
  16. $dane = mysql_fetch_array($wynik);
  17. $_SESSION["koszyk"]["$id"]["towar"]=$dane["nazwa"];
  18. $_SESSION["koszyk"]["$id"]["cena"]=$dane["cena_detaliczna"];
  19.  
  20. if ($sz=="") $_SESSION["koszyk"]["$id"]["ile"]++;
  21. else if ($sz>=1) $_SESSION["koszyk"]["$id"]["ile"]=$sz;
  22. else if ($sz<=0) unset($_SESSION["koszyk"]["$id"]);
  23. }
  24. }
  25.  
  26.  
  27. if (count($_SESSION["koszyk"])>0) {
  28. echo "<table border=0>
  29. <colgroup>
  30. <col />
  31. <col align=\"right\" />
  32. <col align=\"center\" />
  33. <col align=\"center\" />
  34. <col align=\"right\" />
  35. </colgroup>
  36. <tr><th bgcolor=#9999ff>towar</th><th bgcolor=#9999ff>cena</th><th bgcolor=#9999ff>sztuk</th><th bgcolor=#9999ff>łącznie</th></tr>";
  37.  
  38. foreach($_SESSION["koszyk"] as $indeks=>$kosz) {
  39. echo "<tr>";
  40. echo "<td>{$kosz["towar"]}</td>";
  41. echo "<td align=right>{$kosz["cena"]} zł</td>";
  42. echo "<td>
  43. <form action=koszyk.php method=get style=display:inline;>
  44. <div style=\"display:inline;\">
  45. <input type=hidden name=id value=$indeks>
  46. <input type=text name=sz value=\"{$kosz["ile"]}\" style=\"width:25px;\" >
  47. <input type=submit value=zmień style=\"width:45px;\" >
  48. </div></form>
  49. <form action=koszyk.php method=get style=\"display:inline;\">
  50. <div style=\"display:inline;\">
  51. <input type=hidden name=id value=$indeks />
  52. <input type=hidden name=sz value=0 style=\"width:25px;\" />
  53. <input type=submit value=usuń style=\"width:45px;\" />
  54. </div></form>
  55. </td>";
  56.  
  57. echo "<td align=right>".number_format($kosz["cena"]*$kosz["ile"],2,".","");
  58. echo " zł</td>";
  59. echo "</tr>";
  60. $lacznie +=$kosz["cena"]*$kosz["ile"];
  61. }
  62. echo "<tr><td colspan=\"3\" align=\"right\">
  63. <b>w sumie: </td><td align=right><b>";
  64. echo number_format($lacznie,2,".","")." zł</td></tr>";
  65. echo "</table>";


i do niego dodałam:
  1. function odbierz($txt) {
  2. if (get_magic_quotes_gpc()) $txt = stripslashes($txt);
  3. return str_replace(array('\\',"'"), array('\\\\',"\'"), trim($txt));
  4. }
  5.  
  6.  
  7. $id = odbierz($_REQUEST["id"]);
  8. $sz = isset($_REQUEST["sz"])?number_format($_REQUEST["sz"],0,".",""):"";
  9.  
  10. if ($id<>"") {
  11. if (mysql_connect($sql_serwer, $sql_login, $sql_haslo)
  12. and mysql_select_db($sql_baza)) {
  13. $wynik = mysql_query("SELECT * FROM ehi_produkty WHERE id_produktu='$id'");
  14. }
  15. if ($wynik and mysql_num_rows($wynik)==1) {
  16. $dane = mysql_fetch_array($wynik);
  17. $_SESSION["koszyk"]["$id"]["towar"]=$dane["nazwa"];
  18. $_SESSION["koszyk"]["$id"]["cena"]=$dane["cena_detaliczna"];
  19. $_SESSION["koszyk"]["$id"]["gabaryty"]=$dane["gabaryty"];
  20.  
  21. if ($sz=="") $_SESSION["koszyk"]["$id"]["ile"]++;
  22. else if ($sz>=1) $_SESSION["koszyk"]["$id"]["ile"]=$sz;
  23. else if ($sz<=0) unset($_SESSION["koszyk"]["$id"]);
  24. }
  25. }
  26.  
  27.  
  28. if (count($_SESSION["koszyk"])>0) {
  29. echo "<table border=0>
  30. <colgroup>
  31. <col />
  32. <col align=\"right\" />
  33. <col align=\"center\" />
  34. <col align=\"center\" />
  35. <col align=\"right\" />
  36. </colgroup>
  37. <tr><th bgcolor=#9999ff>towar</th><th bgcolor=#9999ff>gabaryt</th><th bgcolor=#9999ff>cena</th><th bgcolor=#9999ff>sztuk</th><th bgcolor=#9999ff>łącznie</th></tr>";
  38.  
  39. foreach($_SESSION["koszyk"] as $indeks=>$kosz) {
  40. echo "<tr>";
  41. echo "<td>{$kosz["towar"]}</td>";
  42. echo "<td>{$kosz["gabaryty"]}</td>";
  43. echo "<td align=right>{$kosz["cena"]} zł</td>";
  44. echo "<td>
  45. <form action=koszyk.php method=get style=display:inline;>
  46. <div style=\"display:inline;\">
  47. <input type=hidden name=id value=$indeks>
  48. <input type=text name=sz value=\"{$kosz["ile"]}\" style=\"width:25px;\" >
  49. <input type=submit value=zmień style=\"width:45px;\" >
  50. </div></form>
  51. <form action=koszyk.php method=get style=\"display:inline;\">
  52. <div style=\"display:inline;\">
  53. <input type=hidden name=id value=$indeks />
  54. <input type=hidden name=sz value=0 style=\"width:25px;\" />
  55. <input type=submit value=usuń style=\"width:45px;\" />
  56. </div></form>
  57. </td>";
  58.  
  59. echo "<td align=right>".number_format($kosz["cena"]*$kosz["ile"],2,".","");
  60. echo " zł</td>";
  61. echo "</tr>";
  62. $lacznie +=$kosz["cena"]*$kosz["ile"];
  63. }
  64. echo "<tr><td colspan=\"3\" align=\"right\">
  65. <b>w sumie: </td><td align=right><b>";
  66. echo number_format($lacznie,2,".","")." zł</td></tr>";
  67. echo "</table>

czyli zmienna gabaryty. Niestety zmienna gabaryty nie chce się wyświetlać.

Gdzie robie błąd?

Ten post edytował agataperz 7.10.2011, 17:38:32
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
mls
post
Post #2





Grupa: Zarejestrowani
Postów: 677
Pomógł: 89
Dołączył: 31.08.2003
Skąd: Warszawa

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


To "coś" (bo kodem to ciężko nazwać) to jedna wielka masakra. Tylu błędów dawno nie widziałem... Ale cóż...
Co do problemu - może po prostu nie masz w tabeli sql kolumny o nazwie "gabaryty", lub jest ona pusta.
Go to the top of the page
+Quote Post
agataperz
post
Post #3





Grupa: Zarejestrowani
Postów: 182
Pomógł: 0
Dołączył: 24.03.2009
Skąd: Hamburg DE

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


w tym problem ze mam
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: 22.08.2025 - 20:04