1

I am trying to use php to set session variables on the initial loginPage.php and show up on the paymentPage.php but I am having troubles setting the $_SESSION variables so that it shows up. There is a web page in between the loginPage and the paymentPage and that seems to be tripping me up.

Also, I need to calculate a total of the selected items on the previous page but I am unsure how put a dollar amount with a checkbox that does not show but calculates the total on the 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>

3 Answers 3

1

Look I really looked through your code and I don't know if there's something missing but I doesn't make too much sense for me. Anyway if it works for you it's fine.

Here's a Typo that I found:

paymentPage.php

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

And for your calculation.. I don't know man. You made the dom a little bit to static to get these values foreach product or whatever. The best thing you can do is to give every element a unique Id oder class and than validate it via JS to see if it got checkt or not. There's still a long way for you.. But remember we don't write your code.

Sign up to request clarification or add additional context in comments.

1 Comment

I appreciate your honesty, I am very new to this as I have never worked with HTML or PHP before. I will take your suggestions and see what I can come up with! I wasn't expecting you to give me code, just some pointers on what I need to improve and what you think of my problems. Thank you!
1

You forgot to ask a question and to explain your problem.

Any page which is accessing the session must(1) start with a PHP block containing session_start(). Only 1 of the the 4 scripts you've shown us does this.

1) Not strictly true - but a discussion of the exceptions is too complex to go into here

1 Comment

Ok, so every single page needs to contain session_start() in order for the variables to be passed to other pages? I will work on that to correct my issue. I guess my questions were 1) why are my variables not being passed to the other pages and 2) in word form, how should I go about getting a total dollar amount on the paymentPage.php from the EquineShop.php page. Not looking for code, but I can't seem to wrap my head around it. Thank you for your help!
0

Another problem i found is on your thankyou page:

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

What I think you are trying to do: You are trying to make a form that removes all your session variables when you click the submit button.

What you are actually doing:

You are rendering a form that on submit wil send a POST to loginPage.php. and while you are building this form on the server you are also already unsetting the Session variables. As the code above equals the code i show you here below:

<?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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.