2017-04-04 1 views
1

私は最初のloginPage.phpでセッション変数を設定するためにphpを使用しようとしていますが、paymentPage.phpに表示していますが、$ _SESSION変数を設定する現れます。 loginPageとpaymentPageの間にはWebページがあり、それは私を驚かせるようです。セッション変数を設定し、他の.phpファイルから計算する

また、前のページで選択したアイテムの合計を計算する必要がありますが、表示されていないがpaymentPageの合計を計算するチェックボックスで金額を入力する方法がわかりません。

loginPage.php

<?php 

    session_start(); 

?> 

<html> 

<head> 

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 

    <title>Form Login</title> 

</head> 



<body OnLoad="document.main.username.focus();"> 

    <table> 

    <tr> 

     <td colspan="2"> 

     <h2>Welcome to the Equine Shop!</h2> 

     <h4>Please enter a personalized Username, Email Address and Password to continue to our online store</h4> 

     </td> 

    </tr> 

    <!-- create the main form with an input text box named uid and a password text box named mypassword --> 

    <form name="main" method="post" action="EquineShop.php"> 

     <form action="paymentPage.php" method=post> 

     <tr> 

      <td>Username:</td> 

      <td><input type="text" name="username" type="text" size="50"></td> 

     </tr> 

     <tr> 

      <td>Email Address:</td> 

      <td><input type="text" name="emailadd" type="text" size="50"></td> 

     </tr> 

     <tr> 

      <td>Password:</td> 

      <td><input type="password" name="pass" type="text" size="50"></td> 

     </tr> 

     <tr> 

      <td colspan="2" align="center"><input name="btnsubmit" type="submit" value="Submit"></td> 

     </tr> 

    </table> 

    </form> 

    </form> 

</body> 

</html> 

EquineShop.php

<html> 

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Equine Shop Home Page </title> 
</head> 

<?php 
    if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) { 
     session_unset(); 
     session_destroy(); 
    } 
    $_SESSION['LAST_ACTIVITY'] = time(); 
    ?> 

    <body OnLoad="document.main.username.focus();"> 

    <form name="main" method="post" action="paymentPage.php"> 

     <h1 style="text-align:center;">Welcome to the Equine Shop!</h1> 
     <table border="5"> 
     <tr> 
      <td> 
      <p style="font-size:24px;">Halters</p> 
      <p>$25.00</p> 
      <p>Built to last, these halters are made of premium quality</p> 
      <p><a href="http://localhost/week2/halters.html">Click for more details!</a></p> 
      <p><img src="https://www.valleyvet.com/swatches/35434_S_001_vvs.jpg" width="300" height="250" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Saddle Pads</p> 
      <p>$37.00</p> 
      <p>You'll love this all purpose saddle pad!</p> 
      <p><a href="http://localhost/week2/saddlepad.html">Click for more details!</a></p> 
      <p><img src="https://img.smartpak.com/images/product/20333_Navy.jpg" width="300" height="250" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Girths</p> 
      <p>$200.00</p> 
      <p>This leather english girth is made of quality leather.</p> 
      <p><a href="http://localhost/week2/girths.html">Click for more details!</a></p> 
      <p><img src="https://img.smartpak.com/images/product/highres/14428_Chocolate_Top_silo.jpg?width=460&quality=100" width="300" height="250" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">English Saddles</p> 
      <p>$2,200.00</p> 
      <p>Soft and comfortable padding with adjustable tree.</p> 
      <p><a href="http://localhost/week2/englishsaddles.html">Click for more details!</a></p> 
      <p><img src="https://s-media-cache-ak0.pinimg.com/736x/9a/82/6d/9a826d879d8fbea19fe167f267b0d61f.jpg" width="300" height="300" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Bridles</p> 
      <p>$150.00</p> 
      <p>This plain raised flash bridles delivers complete comfort.</p> 
      <p><a href="http://localhost/week2/bridles.html">Click for more details!</a></p> 
      <p><img src="https://www.equestrianweb.com/media/catalog/product/cache/1/image/650x650/7d70730b2ff80c936b5c98bf27fe5aba/e/c/ec18-geral.jpg" width="300" height="300" /></p> 
      </td> 
     </tr> 

     <tr> 
      <td> 
      <p style="font-size:24px;">Grooming Materials</p> 
      <p>$85.00</p> 
      <p>The complete grooming kit!</p> 
      <p><a href="http://localhost/week2/grooming.html">Click for more details!</a></p> 
      <p><img src="https://s-media-cache-ak0.pinimg.com/236x/57/db/22/57db225ed12aa5c8009c4861ad6873cb.jpg" width="300" height="300" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Blankets</p> 
      <p>$150.00</p> 
      <p>1680 denier, turnout, waterproof blanket.</p> 
      <p><a href="http://localhost/week2/blankets.html">Click for more details!</a></p> 
      <p><img src="http://cdnll.doversaddlery.com/images/xl/0024378.jpg" width="300" height="300" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Sheets</p> 
      <p>$124.00</p> 
      <p>1200 denier, turnout waterproof sheet.</p> 
      <p><a href="http://localhost/week2/sheets.html">Click for more details!</a></p> 
      <p><img src="http://cdnll.doversaddlery.com/images/xl/0024280.jpg" width="300" height="300" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Fly Masks</p> 
      <p>$30.00</p> 
      <p>Keep flys off your horses face this summer!</p> 
      <p><a href="http://localhost/week2/flymasks.html">Click for more details!</a></p> 
      <p><img src="https://img.smartpak.com/images/product/highres/21540_Standard_WEars.jpg?width=460" width="300" height="300" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">First Aid</p> 
      <p>$100.00</p> 
      <p>The complete first aid kit for your horse</p> 
      <p><a href="http://localhost/week2/firstaid.html">Click for more details!</a></p> 
      <p><img src="http://cdnll.doversaddlery.com/images/xl/0011304.jpg" width="300" height="300" /></p> 
      </td> 
     </tr> 

     <tr> 
      <td> 
      <p style="font-size:24px;">Spurs</p> 
      <p>$45.00</p> 
      <p>These soft touch spurs are great for sensitive horses</p> 
      <p><a href="http://localhost/week2/spurs.html">Click for more details!</a></p> 
      <p><img src="https://img.smartpak.com/images/product/300x300/19089.jpg?width=224&quality=100" width="300" height="300" /></p> 
      </td> 

      <td> 
      <p style="font-size:24px;">Whips</p> 
      <p>$50.00</p> 
      <p>Dressage whips for optimum riding</p> 
      <p><a href="http://localhost/week2/whips.html">Click for more details!</a></p> 
      <p><img src="https://ii.bigdweb.com/fcgi-bin/iipsrv.fcgi?FIF=/images/bigdweb/source/3011f_c1105.tif&qlt=75&wid=225&cvt=jpeg" width="300" height="300" /></p> 
      </td> 
     </tr> 
     </table> 


     <p style="font-size:20px;"><b> Order Form</b></p> 
     First Name:<br> 
     <input type="text" name="firstname"><br> Last Name:<br> 
     <input type="text" name="lastname"><br> Street Address:<br> 
     <input type="text" name="street"><br> City: 
     <br> 
     <input type="text" name="city"><br> State: 
     <br> 
     <input type="text" name="state"><br> Zip: 
     <br> 
     <input type="text" name="zip"><br> 
     <br> 

     <table> 
     Product: 
     <tr> 
      <td><input type="checkbox" name="tack[]" value="Halter">Halter</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="SaddlePad">Saddle Pad</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="Girth">Girth</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="Saddle">English Saddle</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="Bridle">Bridle</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="Grooming">Grooming Material </td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="Blanket">Blanket</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="FirstAid">First Aid</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="spur">Spur</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 

     <tr> 
      <td><input type="checkbox" name="tack[]" value="Whip">Whip</td> 
      <td>Quantity: <select name="quantity"> 
          <option>0</option> 
          <option>1</option> 
          <option>2</option> 
          <option>3</option> 
          <option>4</option> 
         </select></td> 
     </tr> 
     </table> 

     <br><input type="submit" value="Proceed to Checkout" /> 

    </form> 
    </body> 

</html> 

paymentPage.php

<html> 

<head> 

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 

    <title>Equine Shop Payment Form</title> 

</head> 

<body> 

    <?php 

     // Display in a table  

     echo "<h1> Equine Shop Payment Form </h1>"; 

     echo "<table border='1'>"; 

     echo "<tr> 

      <th>User Name</th> 

      <th>E-mail Address</th> 

      </tr>"; 

     echo "<tr> 

      <td>$_SESSION['username']</td> 

      <td>$_SESSION['emailadd']</td> 

      </tr>"; 

     echo "</table><br><br>";  

?> 



    <?php 

    $selected = $_POST['tack']; 

     if(empty($selected)){ 

      echo("You didn't select any products!"); 

     } else { 

      $checked = count($selected); 

      echo("<b>Shopping Cart: </b><br><br>"); 

      for($i = 0; $i < $checked; $i++) { 

       echo($selected[$i] . "<br>"); 



      } 

     } 

?> 

     <br><br> 

     <?php 

    echo "<b>Total: </b>" 

?> 



     <form> 

      <br><br>Credit Card Type:<br> 

      <input type="radio" name="ccard" <?php if (isset($ccard) && $ccard=="visa") echo "checked";?> value="visa">Visa 

      <br> 

      <input type="radio" name="ccard" <?php if (isset($ccard) && $ccard=="master") echo "checked";?> value="master">MasterCard 

      <br> 

      <input type="radio" name="ccard" <?php if (isset($ccard) && $ccard=="discover") echo "checked";?> value="discover">Discover 

      <br> 

      <input type="radio" name="ccard" <?php if (isset($ccard) && $ccard=="amex") echo "checked";?> value="amex">American Express<br> 

     </form> 

     <br> Card Number:<br> 

     <input type="text" name="card" maxlength="16"> 

     <br> Exp Date:<br> 

     <input type="text" name="exp" maxlength="4"> 

     <br> Security Number:<br> 

     <input type="text" name="secnum" maxlength="3"> 

     <br> 



     <form action=""> 

      Comments:<br> 

      <input type="text" name="comments" maxlength="300"><br> 

     </form> 



     <form name="main" method="post" action="thankYou.php"> 

      <input type="submit" value="Submit Order"> 

     </form> 

</body> 

</html> 

thankYou.php

<html> 

<head> 
    <title> Thank You for your Purchase! </title> 
</head> 

<body> 
    <?php 
    echo "<b>Thank you for your Purchase!</b>" 
?> 
    <br> 
    <?php 
    echo "Your order will be processed immediatley and arrive within 7 - 10 business days" 
?> 

    <br><br> 
    <form name="main" method="post" action="loginPage.php"> 
     <input type="submit" value="Log Out" /> 
     <?php 
     session_unset(); 
     session_destroy(); 
    ?> 
    </form> 
</body> 

</html> 

答えて

1

見て私は本当にあなたのコードを見て、何か欠けがあるかどうかはわからないが、私は私のためにあまり意味がありません。とにかくそれがあなたのために働くならば、それは大丈夫です。

ここで私が見つけた誤植だ:

paymentPage.php

echo "<tr> 
     <td>" . $_SESSION['username'] . "</td> 
     <td>" . $_SESSION['emailadd'] . "</td> 
    </tr>"; 

そして、あなたの計算のためには..私は男を知りません。あなたは、これらの値をforeach製品やその他のものにするために、domを少し静的にしました。あなたが行うことができる最も良いことは、すべての要素に一意のIDクラスを与え、JSを介してチェックしてチェックがあるかどうかを確認することです。あなたにはまだ長い道のりがあります。しかし、私たちはあなたのコードを書いていないことを忘れないでください。

+0

あなたの正直を感謝します。これまで私はHTMLやPHPでこれまで作業したことがないので、これは初めてです。私はあなたの提案を受け取り、私が思いつくことができるものを見るでしょう!私はあなたに私のコードを与えることを期待していなかった、私は改善する必要があるもののいくつかの指針と私の問題を考える。ありがとうございました! – pCaMp

1

あなたは質問をして問題を説明するのを忘れました。

にアクセスしているページは、session_start()を含むPHPブロックで始まり、(1)で始まる必要があります。あなたが私たちに示した4つのスクリプトのうち1つだけがこれを行います。

1)厳密には正しくありません - しかし、例外の議論はここで

+0

他のページに変数を渡すために、各ページにsession_start()を入れる必要がありますか?私はそれを修正して問題を解決します。私の質問は、1)私の変数が他のページに渡されていない理由、2)単語形式で、EquineShop.phpページからpaymentPage.phpの総額を取得する方法を教えてください。コードを探しているわけではありませんが、私の周りに頭を包んでいるようです。ご協力ありがとうございました! – pCaMp

0

私が見つけたもう一つの問題は、あなたのありがとうのページにあるに入るには余りにも複雑である:

<form name="main" method="post" action="loginPage.php"> 
    <input type="submit" value="Log Out" /> 
    <?php 
    session_unset(); 
    session_destroy(); 
?> 
</form> 

私はあなたがしようとしていると思いますどのような目的:送信ボタンをクリックすると、すべてのセッション変数を削除するフォームを作成しようとしています。あなたは上のloginPage.phpにPOSTを送信ウィル提出フォームをレンダリングしている

:あなたが実際に何をしている

。サーバー上でこのフォームを作成している間も、すでにセッション変数の設定を解除しています。上記のコードがコードと同じであるため、私は以下のコードを表示します:

<?php //deleting session state 
    session_unset(); 
    session_destroy(); 
//now lets output some html, being a form: 
?>  
<form name="main" method="post" action="loginPage.php"> 
    <input type="submit" value="Log Out" /> 
</form> 
関連する問題