Hi,
I am building a simple online shop. I found a cart and added a form, everything seems to be working ok, but now I have to pass the final content through a hidden input to the external payment system.
I need to pass the DESCRIPTION of each choosen item (a course), which will include (1) type of a course, date when it starts and ends, (2) how many places are chosen, (3) what is the price per unit and a TOTAL PRICE for all items.
I got to the point where after user choses everything and fills in the form with a name and address, I amended the cart function, so it will display results on a page without giving the user any more chance to change it and at this point I want to include a 'Proceed to secure payment' button.
The courses and prices are pulled from MySql database and I don't know how to pass the information further. I have it in two separate functions and somebody suggested putting it in one to avoid using global variables, but it still didn't work and on the new page where the payment should be proceed i am getting error that the total is not a valid value and the description is blank.
How can I pass the values from my function? please see the code below:
//I'm displaying the final choice on the page with function checkout
function checkout() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<table border="1" id="shop">';
$output[] = '<tr>';
$output[] = '<td><strong>Item</strong>
</td>';
$output[] = '<td><strong>Quantity</str
ong></td>'
;
$output[] = '<td><strong>Total per item</strong></td>';
$output[] = '</tr>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM courses WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td><strong>'.$title.'</s
trong> <br /> '.$start_date.' '.$end_date.' <br /> '.$weeks.'</td>';
$output[] = '<td>'.$qty.'</td>';
$output[] = '<td>£'.($price * $qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '<tr >';
$output[] = '<td colspan="2"><strong>Total for all items:</strong></td>';
$output[] = '<td colspan="2"><strong>£
;'.$total.
'</strong>
</td>';
$output[] = '</tr>';
$output[] = '</table>';
$output[] = '<p> </p>';
}
return join('',$output);
}
//I want to pass the description for each chosen course (which will include $title $start_date $end_date $weeks as well as how many of those courses are purchases ($qty) and what is the price per course ($price)) and apart from that list a total price for all, I'm putting it in the form, which will direct me to the secure server, but unfortunately the values don't go through:
<form action="
https://xxx.com" method=POST target="_blank">
<input type=hidden name="testMode" value="123">
<input type=hidden name="instId" value="1234">
<input type=hidden name="cartId" value="1234567">
<input type=hidden name="amount" value="<?php print $title; ?>">
<input type=hidden name="currency" value="GBP">
<input type=hidden name="desc" value="<?php print $title . '</strong> <br /> ' . $start_date . ' ' . $end_date . ' <br /> (' . $weeks . ') x ' . $qty; ?>">
<input type=hidden name="name" value="<?php print htmlspecialchars($_POST['f
irstname']
) . ' ' . htmlspecialchars($_POST['l
astname'])
; ?>">
<input type=hidden name="address" value="<?php print (htmlspecialchars($_POST['
address'])
. ', ' . htmlspecialchars($_POST['t
own'])); ?>">
<input type=hidden name="postcode" value="<?php print htmlspecialchars($_POST['p
ostcode'])
; ?>">
<input type=hidden name="country" value="<?php print htmlspecialchars($_POST['c
ountry']);
?>">
<input type=hidden name="tel" value="<?php print htmlspecialchars($_POST['t
elephone']
); ?>">
<input type=hidden name="email" value="<?php print htmlspecialchars($_POST['e
mail']); ?>">
<input type=submit value="Proceed to secure server">
</form>
Please note, that I am a beginner in PHP. :)
Thank you!
j.