Complete novice looking for help...
Posted: Sat Mar 15, 2008 12:32 pm
Hi...
I am currently helping a friend to try and build a site that has a shopping basket which will allow customers to then go and pay with paypal..
The problem I am having is sending the info through to paypal.
I have taken some really nice code offered by a chap on his site called the watchmaker project which was really easy to follow and amend as necessary. It uses a session to store the basket info.
The problem I am now having is using the html form offered by paypal to send the individual item details through to them.
I have created a new function to do this as my level of understanding requires and I have nearly got it working... the problem here in the code underneath is that there is a foreach statement which is causing the loop to loop through a number of times for each item in the basket. Therefore I now have two instances of each item if I have two items in the basket, three instances of each item if there are three items in the basket and so on and so forth.
I have tried to remove the foreach statement but this produces all sorts of errors..
Any help on removing this would be greatly appreciated.. I am a complete novice and apologise for the lack of understanding on my part. I have certainly leapt straight in and this has obviously caused me problems.
thanks in advance
Chris
function sendtopaypal()
{
global $db;
$cart = $_SESSION['cart'];
$item = 0;
$i=1;
if ($cart)
{
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item)
{
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
echo "<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>";
echo "<input type='text' name='cmd' value='_cart'/>";
echo "<input type='text' name='upload' value='1'/>";
echo "<input type='text' name='business' value='katie.photoangel@googlemail.com'/>";
for($i=1; $i <= count($contents); $i++)
{
echo $i;
foreach ($contents as $id=>$qty)
{
$sql = 'SELECT * FROM products1 WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
echo "<input type='text' name='item_name_$i' value='".$sweet."'/>";
echo "<input type='text' name='amount_$i' value='".$price."'/>";
}
}
}
echo "<input type='submit' value='Pay securely with Paypal'/>";
echo "</form>";
}
?>
I am currently helping a friend to try and build a site that has a shopping basket which will allow customers to then go and pay with paypal..
The problem I am having is sending the info through to paypal.
I have taken some really nice code offered by a chap on his site called the watchmaker project which was really easy to follow and amend as necessary. It uses a session to store the basket info.
The problem I am now having is using the html form offered by paypal to send the individual item details through to them.
I have created a new function to do this as my level of understanding requires and I have nearly got it working... the problem here in the code underneath is that there is a foreach statement which is causing the loop to loop through a number of times for each item in the basket. Therefore I now have two instances of each item if I have two items in the basket, three instances of each item if there are three items in the basket and so on and so forth.
I have tried to remove the foreach statement but this produces all sorts of errors..
Any help on removing this would be greatly appreciated.. I am a complete novice and apologise for the lack of understanding on my part. I have certainly leapt straight in and this has obviously caused me problems.
thanks in advance
Chris
function sendtopaypal()
{
global $db;
$cart = $_SESSION['cart'];
$item = 0;
$i=1;
if ($cart)
{
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item)
{
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
echo "<form action='https://www.paypal.com/cgi-bin/webscr' method='post'>";
echo "<input type='text' name='cmd' value='_cart'/>";
echo "<input type='text' name='upload' value='1'/>";
echo "<input type='text' name='business' value='katie.photoangel@googlemail.com'/>";
for($i=1; $i <= count($contents); $i++)
{
echo $i;
foreach ($contents as $id=>$qty)
{
$sql = 'SELECT * FROM products1 WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
echo "<input type='text' name='item_name_$i' value='".$sweet."'/>";
echo "<input type='text' name='amount_$i' value='".$price."'/>";
}
}
}
echo "<input type='submit' value='Pay securely with Paypal'/>";
echo "</form>";
}
?>