ID fra database skal vise tekst til Paypal
Hej alle!I min webshop her (der nu er næsten færdigbygget takket være jeres fine hjælp :)):
http://www.carlinart.net/shoppingcart/cart.php?action=add&id=1
vil varerne man køber, fremstå i Paypal som det nummer de er givet i min MySql database som id. Her er et screenshot af hvordan det ser ud:
http://img119.imageshack.us/img119/1717/paypaltg2.jpg
De har altså ingen titel på kundens kvittering, men vil hedde 1, 2, 3, 4 afhængig af rækkefølgen jeg har sat dem op. Her er et billede af hvordan id'erne ser ud i min database:
http://img119.imageshack.us/img119/9402/databaseku4.jpg
Jeg har prøvet sådan noget som at kalde dem 1_Fischer, 2_Nakamura, men det er stadig kun tal der vises. Hvis jeg helt fjerner tallet og indsætter tekst, står paypal af og viser tom kurv fejl. Så det må være sådan at php scriptningen behøver et tal som id, men er der nogen her som har en ide til hvordan jeg kunne få vist bare nogle få bogstaver sammen med det i paypal? Det ville være rart hvis mine kunder kunne se hvad de køber.
Her er koden fra mit cart script:
<?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Print Shop</title>
<link rel="stylesheet" href="css/styles.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head>
<body>
<div id="apDiv11"><?php
function getTotalPrice() {
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;
}
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM books WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$total += $price * $qty;
}
}
return $total;
}
?></div>
<div id="apDiv10"><?php
function getTotalContents() {
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;
}
}
return $cart;
}
?></div>
<div id="contents">
<h1 class="style37 style39">Your print basket:</h1>
<p class="style37 style39"> </p>
<?php
echo writeShoppingCart();
?>
<?php
echo showCart();
?>
<br/>
<form>
<input type="button" class="red" onclick="window.location.href='index.php'" value="Go back to print selection"/>
</form>
<p> </p>
<p>Click the shiny Paypal button when you're ready to checkout. You will be taken to Paypal's site to enter shipping and billing information. </p>
<p> </p>
<p align="left">Thank you for supporting my art!</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<div align="center">
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="carina2b@hotmail.com"/>
<input type="hidden" name="item_name_1" value="<?php echo getTotalContents(); ?>"/>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="amount_1" value="<?php echo getTotalPrice(); ?>"/>
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</div>
</form>
</div>
</body>
</html>
Her er koden fra det script der håndterer shopping cartens sammentælninger:
<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>You have no prints in your print basket</p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '<p>You have picked <a class="hvidvin">'.count($items).' print'.$s.'.</a></p><br/>';
}
}
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" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM books WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td>'.$title. ' <br/>Size: '.$author.'</td>';
$output[] = '<td>Amount (click to edit) : <input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>Price: € '.($price * $qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<div><button type="submit">Update basket</button></div>';
$output[] = '<p>Total price in euros: <strong>€ ' .$total.'</strong></p>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
}
?>