Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] przeslanie zmiennej do funkcji
Spyder
post
Post #1





Grupa: Zarejestrowani
Postów: 269
Pomógł: 7
Dołączył: 12.10.2006
Skąd: Newcastle Upon Tyne

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


witam mam problem mam 2 funkcje

checkout(); i saveorder(); w saveorder wykonuje jakies warunki i przesylam jakas zmienna np $zmienna wiem ze ja dostaje ale teraz jak ja wyslac spowrotem do checkout() w tym ifie

  1. <?php
  2. if ( $check < 14 ){
  3. checkout();  
  4. echo "Minimum Card No 14 digits";
  5. return;
  6. }
  7. ?>


takie cos nie dziala
  1. <?php
  2. if ( $check < 14 ){
  3. checkout();
  4. $zmienna=$_GET['zmienna'];  
  5. echo "Minimum Card No 14 digits";
  6. return;
  7. }
  8. ?>
Go to the top of the page
+Quote Post
rasgan
post
Post #2





Grupa: Zarejestrowani
Postów: 97
Pomógł: 0
Dołączył: 30.05.2007
Skąd: Kleszczów

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


nie działa pewnie dlatego że z GET pobierasz do $zmienna a warunek sprawdzasz dla $check.
Go to the top of the page
+Quote Post
Spyder
post
Post #3





Grupa: Zarejestrowani
Postów: 269
Pomógł: 7
Dołączył: 12.10.2006
Skąd: Newcastle Upon Tyne

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


  1. <?php
  2. if ( $check < 14 ){
  3. checkout();
  4.  
  5. echo "Minimum Card No 14 digits $zmienna ";
  6. return;
  7. }
  8. ?>



Jak zrobie tak to wroci mi do checkout(); i wstawi wartosc zmiennej
Go to the top of the page
+Quote Post
phpion
post
Post #4





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Może pokaż kompletny kod tj. obie funkcje oraz jak je wykorzystujesz. Myślę, że wtedy będzie łatwiej znaleźć rozwiązanie.
Go to the top of the page
+Quote Post
Spyder
post
Post #5





Grupa: Zarejestrowani
Postów: 269
Pomógł: 7
Dołączył: 12.10.2006
Skąd: Newcastle Upon Tyne

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


  1. <? function checkout()
  2. {
  3. if(!isSet($_SESSION['UserId'])){
  4. include_once "sklep_register_form.php";
  5. return;
  6. }
  7.  
  8. if(!isSet($_SESSION['koszyk'])){
  9. $_SESSION['koszyk'] = array();
  10. }
  11.  
  12. if(count($_SESSION['koszyk']) < 1){
  13.  echo("<center><table class='table_red' width='595' height='50' cellpadding='3'>
  14. <tr><td><img src='images/imp.png' style='float:left'><br><center><b> Message !</b>
  15. NO products in Your shopping cart.</center></td></tr></table></center><br>");
  16. return true;
  17. }
  18.  
  19. if(!makeDBConnection()){
  20. echo("<h3 align='center'>Server ERROR</h3>");
  21. return;
  22. }
  23.  
  24. $ids = "";
  25. foreach($_SESSION['koszyk'] as $key => $val){
  26. if($ids == ''){
  27. $ids = $key;
  28. }
  29. else{
  30. $ids .= ", $key";
  31. }
  32. }
  33.  
  34. $userId = $_SESSION['UserId'];
  35.  
  36. $query = "SELECT * FROM product_data WHERE PRODUCT_ID IN($ids) ORDER BY PRODUCT_BRAND";
  37.  
  38.  
  39.  
  40. if(!$result = mysql_query($query)){
  41.  
  42.  echo("<h3 align='center'>No information</h3>");
  43. return;
  44. }
  45. echo("
  46. <form action='index.php?action=saveorder' method='POST'>
  47. <font class='header'>Checkout</font><br>
  48. <table class='table' border='0' align='center' width='600'>
  49. <tr>
  50. <td >Code</td>
  51. <td width='100' >Title</td>
  52. <td >Price</td>
  53. <td align='right'>Quantity</td>
  54. <td align='right'>Line total</td></tr>
  55.  
  56. ");
  57.  
  58. $przesylka = $_GET['przesylka'];
  59. $suma = 0;
  60. while($row = mysql_fetch_row($result)){
  61. echo("<tr>
  62. <td class='textsmall'> $row[1]</td>
  63. <td class='textsmall'>$row[2]</td>
  64. <td class='textsmall'>Ł $row[4]</td>");
  65. $ile = $_SESSION['koszyk'][$row[0]];
  66. $wartosc = $_SESSION['koszyk'][$row[0]] * $row[4];
  67. $wartosc = sprintf("%01.2f", $wartosc);
  68. $suma += $wartosc+$przesylka;
  69. echo("
  70. <td align='right' class='textsmall'>$ile </td>
  71. <td align='right' class='textsmall'>Ł $wartosc </td></tr>
  72. ");
  73. }
  74.  
  75. echo("<tr><td colspan='5' width='600' height='2' background='images/dot.png'></td></tr>");
  76.  
  77. $suma = sprintf("%01.2f", $suma);
  78. echo("
  79. <tr><td colspan='4'>Delivery cost </td><td align='right' class='textsmall'>Ł $przesylka </td></tr>
  80. <tr><td colspan='3'><td>Total</td><td align='right' class='textsmall'>Ł $suma </td></tr></table>
  81. ");
  82.  
  83. $query = "SELECT * FROM customer_data WHERE CUSTOMER_ID = '$userId'";
  84. echo ("
  85. <br><font class='header'>Delivery Address</font><br>");
  86.  
  87.  
  88. $result = mysql_query($query);
  89. while($row = mysql_fetch_row($result)){
  90.  
  91. echo ("
  92. <table class='table' border='0' align='center' width='600'><tr><td>
  93. <center><input type='hidden' name='przesylka' value='$przesylka'> 
  94.  
  95. <table class='bold'><br><br>
  96. <tr><td>Title</td><td><input type='text' name='dtitle' size='30' VALUE='$row[12]' class='form'></td></tr>
  97. <tr><td>Name</td><td><input type='text' name='dname' size='30' VALUE='$row[13]' class='form'></td></tr>
  98. <tr><td>Surname</td><td><input type='text' name='dsurname' size='30' VALUE='$row[14]' class='form'></td></tr>
  99. <tr><td>Address</td><td><input type='text' name='daddress'size='30' VALUE='$row[15]' class='form'></td></tr>
  100. <tr><td>City</td><td><input type='text' name='dcity' size='30' ' VALUE='$row[16]' class='form'></td></tr>
  101. <tr><td>Postcode</td><td><input type='text' name='dpostcode' text' size='30' VALUE='$row[17]' class='form'></td></tr>
  102. <tr><td>Company</td><td><input type='text' name='dcompany' size='30' VALUE='$row[18]' class='form'></td></tr>
  103. <tr><td>Phone</td><td><input type='text' name='dphone' size='30' VALUE='$row[19]' class='form'></td></tr>
  104. </table><br><br>
  105.  
  106.  
  107. <center><table class='table_red' width='585' height='50' cellpadding='3'>
  108. <tr><td><img src='images/imp.png' style='float:left'><br><center><b> Importand !</b>
  109. Delivery address must be identical like address on Your Debit or Credit Card !</center></td></tr></table><br>
  110. </td></tr></table><br>
  111.  
  112. <font class='header'>Payment Method</font>
  113. <table class='table' width='600'><tr><td><br><br>
  114. <table class='bold'border='0' align='center' width=590>
  115. <tr><td width='200'>Payment Method</td><td>"); ?>
  116.  
  117. <select name='method' width='15' class='textsmall' 
  118. onchange="if (this.value == 'card') java script:v('form1'); if (this.value == 'none') java script:h('form1');">
  119. <option>select...</option>
  120. <option name='Credit or Debit Card' value='card' >Credit or Debit Card</option>
  121. <option name='Send Us a Cheque' value='none'>Send Us a Cheque</option>
  122. <option name='Send Us a Postal Order' value='none'>Send Us a Postal Order</option>
  123. <option name='Payment Into Our Bank' value='none'>Payment Into Our Bank</option>
  124. </select>
  125.  
  126.  
  127.  
  128. </td></tr></table>
  129. <DIV ID='form1' STYLE='display: none' class='bold'> 
  130. <table class='bold' border='0' align='center' width=590>
  131. <tr><td>Name on card</td><td><input type='text' name='cardname' size='30' VALUE='<? $cardname ?>' class='form'></td></tr>
  132. <tr><td width='200'>Card Type</td><td>
  133. <select name='cardtype' width='15' class='textsmall' onchange="
  134. if (this.value == 'visa'){ java script: h('issue1'); h('issue2');v('start1');v('start2');}
  135. if (this.value == 'master') {java script:h('issue1'); h('issue2');h('start1');h('start2');}
  136. if (this.value == 'maestro') {java script:v('issue1'); v('issue2');v('start1');v('start2');}
  137. if (this.value == 'solo') {java script:v('issue1'); v('issue2');v('start1');v('start2');}
  138. if (this.value == 'jcb') {java script:v('issue1'); v('issue2');v('start1');v('start2');}
  139. if (this.value == 'american') {java script:h('issue1'); h('issue2');h('start1');h('start2');}
  140. ">
  141. <option>select...</option>
  142. <option name='Visa' value='visa'>Visa/Visa Electron</option>
  143. <option name='Mastercard' value='master'>Mastercard</option>
  144. <option name='Maestro/Switch' value='maestro'>Maestro/Switch</option>
  145. <option name='American Express' value='american'>American Express</option>
  146. <option name='Solo' value='solo'>Solo</option>
  147. <option name='JCB' value='jcb'>JCB</option>
  148. </select>
  149.  
  150.  
  151. </td></tr>
  152.  
  153. <tr><td>Card Number</td><td><input type="text" name="cardno" maxlength="19" size="30" VALUE="<? $cardno ?>" class="form" ></td></tr>
  154. <tr><td>Security No.</td><td><input type="text" name="security" size="4" VALUE="<? $security ?>" MAXLENGTH="4" class="form">
  155. <font class="textsmall">(3 digits on back of card, 4 digits for Amex)</font></td></tr>
  156.  
  157.  
  158. <tr><td><div ID="issue1" STYLE="display:none; margin:0">Issue No.</div></td><td>
  159. <div ID="issue2" STYLE="display:none; margin:0" >
  160. <input type="text" type="text" size="1" VALUE="<? $issueno ?>" MAXLENGTH="1" class="form">
  161. <font class="textsmall">(if present)</font></div></td></tr>
  162.  
  163. <tr><td><div id="start1" STYLE="display: none; margin:0">Valid From</div></td><td>
  164. <div id="start2" STYLE="display: none; margin:0">
  165. <input type="text" name="sm" size="1" VALUE="<? $sm ?>" class="form"> /
  166. <input type="text" name="sy" size="1" VALUE="<? $sy ?>" class="form">
  167. <font class="textsmall">(e.g. 02/04)</div>
  168. </td></tr>
  169. <tr><td>Expires</td><td>
  170. <input type="text" name="em" size="1" VALUE="<? $em ?>" class="form"> /
  171. <input type="text" name="ey" size="1" VALUE="<? $ey ?>" class="form"><font class="textsmall">(e.g. 11/06)
  172. </td></tr>
  173. </table></div>
  174.  
  175. <table class='bold'border='0' align='center' width=590>
  176. <tr><td width='200'>Additional Information</td><td>
  177. <? echo ("
  178. <TEXTAREA NAME='comments' COLS=30 ROWS=4 class='form' class='form'></TEXTAREA><br>
  179. <font class='textsmall'>If you found us using a search engine or cost comparison
  180. site, please tell us which one you used.</font>
  181. </td></tr></table></div><br>
  182. ");
  183. }
  184.  
  185.  echo("<center><input class='button' type='submit' value='Finish shopping'></center><br><br>
  186.  
  187. <a href='java script:history.back%20()' class='back'>Ť Back to Shopping card</a>
  188. </td></tr></table>
  189.  
  190.  
  191. ");
  192.  
  193.  
  194. }
  195. function clear()
  196. {
  197.  
  198. if(isSet($_SESSION['koszyk'])){
  199. unset($_SESSION['koszyk']);
  200. showBasket();
  201. }
  202.  
  203. }
  204.  
  205.  
  206. function saveorder()
  207. {
  208. $cardtype = $_POST["cardtype"];
  209. $smon = $_POST["sm"];
  210. $syear = $_POST["sy"];
  211. $emon = $_POST["em"];
  212. $eyear = $_POST["ey"];
  213. $cardno = $_POST["cardno"];
  214. $nmon = date("m");
  215. $nyear = date("y");
  216. $method = $_POST["method"];
  217. $sum = $eyear - $nyear;
  218. $sum1 = $emon - $nmon;
  219. $sum2 = $eyear - $syear;
  220. $check = strlen($cardno);
  221. $przesylka = $_POST['przesylka'];
  222.  
  223.  
  224. if ( $method == 'card' ){
  225.  
  226. if ( $cardtype == 'select...' ){
  227. checkout()
  228. ?>
  229. <script>v('form1');</script>
  230. <? 
  231. echo "Select Card Type";
  232. return;
  233. }
  234. if ( $cardtype == 'visa' || $cardtype == 'maestro' || $cardtype == 'solo' || $cardtype == 'jcb' ){
  235.  
  236. if ( $check < 14 ){
  237. checkout();
  238. ?><script>v('form1');</script><?
  239.  
  240. echo "
  241. <center><table class='table_red' width='595' height='50' cellpadding='3'>
  242. <tr><td><img src='images/imp.png' style='float:left'><br><center><b> Message !</b>
  243. Minimum Card No 14 digits</center></td></tr></table>";
  244. return;
  245. }


chodzi i o przeslanie spowrotem zmiennej przesylka z ostatniego ifa do checkout()

juz probuje tak
  1. if ( $check < 14 ){
  2.  
  3. ?><script>v('form1');</script><?
  4.  
  5. checkout(&$przesylka);
  6. echo "
  7. <center><table class='table_red' width='595' height='50' cellpadding='3'>
  8. <tr><td><img src='images/imp.png' style='float:left'><br><center><b>&nbsp;Message !</b>
  9. Minimum Card No 14 digits</center></td></tr></table>";
  10. return;
  11. }
ale nic

Ten post edytował Spyder 4.06.2007, 10:34:33
Go to the top of the page
+Quote Post
rasgan
post
Post #6





Grupa: Zarejestrowani
Postów: 97
Pomógł: 0
Dołączył: 30.05.2007
Skąd: Kleszczów

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


Nie wiem czy to to ale w 58 linii masz
Kod
$przesylka = $_GET['przesylka'];

a zmienną wysyłasz metodą POST, to na razie 1 co znalazłem.
Go to the top of the page
+Quote Post
Spyder
post
Post #7





Grupa: Zarejestrowani
Postów: 269
Pomógł: 7
Dołączył: 12.10.2006
Skąd: Newcastle Upon Tyne

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


Tak bo ta zmienna jest przeslana z funkcji ktora jest nad checkout () w potem jak widac w 93 wysylam ja dalej do saveorder() zeby zapisalo do bazy ale przed ty mam waronki ktore jak nie sa spelnione wracaja do checkout() ale gubia mi przesylke

Czyli dokladnie waronek ten
  1. if ( $check < 14 ){
  2. checkout();
  3. ?><script>v('form1');</script><?
  4.  
  5. echo "
  6. <center><table class='table_red' width='595' height='50' cellpadding='3'>
  7. <tr><td><img src='images/imp.png' style='float:left'><br><center><b> Message !</b>
  8. Minimum Card No 14 digits</center></td></tr></table>";
  9. return;
  10. }


jesli waronek nie jest spelniony wroc do chcekout() + wyslij postem zmienna $przesylka do funkcji Chcekout()
zmienna jest odebrana lini 221 w saveorder() oraz pradzej dla chcekout w 52

chodzi cos w stylu href='index.php?przesylka=$przesylka&action=checkout' tylko tu nie moge tego zastosowac bo nie dziala (IMG:http://forum.php.pl/style_emoticons/default/dry.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: 22.08.2025 - 13:19