1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
  session_start();
  include "includes/connect.php";
  $_SESSION['emailaddress'] = $_GET['email'];
?>

<!DOCTYPE html>

<html lang="en">
  <head>
  <meta charset=utf-8>
  <title>Welcome to The Residency online shop</title>
  <?php
  print_r($_SESSION['cart'])
  ?>
  <!--[if IE]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
    </script>
  <![endif]-->
  <link href="css/reset.css" rel="stylesheet" type="text/css" />
  <link href="css/style.css" rel="stylesheet" type="text/css" />
  <link rel="icon" type="image/png" href="images/favicon.png" />
  
    </head>
    <body>
      <div id="container">
    <div id="header"><!--header open-->
      <div id="logo"><!--logo open-->
        <img src="images/Residency_logo_circle.png" width="175" height="175" alt="The Residency logo" />
      </div><!--logo closed-->
    </div><!--header closed-->
    <center>
    <div id="order"><!--order open-->
      <p>Paypal will use <span><?php print($_SESSION['emailaddress']); ?></span> to process the following order:</p>
      <div id="main_101">
      <table>
          <tr>
            <th>Name</th>
            <th>Quantity</th>
            <th>Price per item</th>
            <th>Total Cost</th>
          </tr>
          <?php
          
            $sql = "SELECT * FROM podcasts WHERE id_podcasts IN (";
              foreach ($_SESSION['cart'] as $id => $value){
                $sql .= $id . ",";  
              }
              $sql = substr($sql,0,-1).") ORDER BY name ASC";
              $query = mysql_query($sql);
              $total_price = 0;
              if(!empty($query)){
              while($row = mysql_fetch_array($query)){
                $subtotal = $_SESSION['cart'][$row['id_podcasts']]['quantity']*$row['price'];
                $total_price += $subtotal;
                ?>
                
                <?php
                $ppname = $row['name'];
                $_SESSION['cart'][$row['id_podcasts']]['name'] = $row['name'];
                $ppquantity = $_SESSION['cart'][$row['id_podcasts']]['quantity'];
                $ppprice= $row['price'];
                ?>
                  <tr>
                    <td><?php echo $row['name'];?></td>
                    <td><?php echo $_SESSION['cart'][$row['id_podcasts']]['quantity'];?></td>
                    <td><?php echo "&pound;" . $row['price'];?></td>
                    <td><?php echo"&pound;" .  $_SESSION['cart'][$row['id_podcasts']]['quantity']*$row['price'];?></td>
                  </tr>
                <?php
              } }
              ?>
              
        
      <tr>
        <td></td>
        <td></td>
        <td><span>Total Price:</td></span>
        <td><span><?php echo"&pound;" .  $total_price;?></td></span>
      </tr>
    </table>
    </div>
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="[email protected]"> <!-- change to your paypal address -->
    <input type="hidden" name="quantity" value="<?php echo $ppquantity;?>"> <!-- do not change, since you refer to it all via the database -->
    <input type="hidden" name="item_name" value="<?php echo $ppname;?>">
    <input type="hidden" name="amount" value="<?php echo $ppprice;?>"> <!-- change here -->
    <input type="hidden" name="shipping" value="0.00">
    <input type="hidden" name="currency_code" value="GBP">
    <input type="hidden" name="custom" value="<?php echo $_SESSION['emailaddress'];?>"> <!-- if you store their purchase in a database, reference the database number here -->
    <input type="hidden" name="return" value="http://shop.residencyradio.com/success.php">
    <span class="input_btn"><input type="submit" name="purchase" value="Purchase" ></span>
    </form>
<?php
  $_SESSION['total_price']=$total_price;
  $_SESSION['emailaddress']=$_GET['email'];
?>
  </div><!--order closed-->

</center></div>

<?php

if (isset($_POST['purchase'])) {
  session_destroy();
  }
?>