I have a shopping cart script inplace and working, to show the cart i call the following function:
function showCart() {
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[] = '<form action="cart.php?action=update" method="post" dvd_id="cart">';
$output[] = '<table>';
$output[] = '<tr>';
$output[] = '<td><b>Title: </b></td>';
$output[] = '<td><b>Price: </b></td>';
$output[] = '<td><b>Quantity: </b></td>';
$output[] = '<td><b>Overall: </b></td>';
$output[] = '<td></td>';
$output[] = '</tr>';
foreach ($contents as $dvd_id=>$qty) {
$sql = 'SELECT * FROM dvds WHERE dvd_id = '.$dvd_id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td>'.$title.' </td>';
$output[] = '<td>£'.$price.' </td>';
$output[] = '<td><input type="text" name="qty'.$dvd_id.'" value="'.$qty.'" size="2" maxlength="2" /> </td>';
$output[] = '<td>£'.($price * $qty).' </td>';
$total += $price * $qty;
$output[] = '<td><a href="cart.php?action=delete&dvd_id='.$dvd_id.'" class="r">Remove</a></td>';
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>';
$output[] = '<div><button type="submit">Update cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
}
I want to use a paypal checkout where users can buy the items in the cart, i'm using this form:
form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="freemanz24@hotmail.com">
<input type="hidden" name="item_name" value="<?php echo $_POST['item']; ?>">
<input type="hidden" name="item_number" value="<?php echo $_SESSION['dvd_id']; ?>">
<input type="hidden" name="amount" value="<?php echo $_POST['price']; ?>">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="bn" value="PP-ShopCartBF">
</form>]
For the values for item name, number and amount i want it to send the variables across to the paypal cart page, i'm not sure to call these variables correctly which i'm trying to extract from the showcart function.
Could anyone help me with this?