passing items to paypal

This is a discussion on "passing items to paypal" within the PHP Forum section. This forum, and the thread "passing items to paypal are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jun 8th, 2007, 18:51
Reputable Member
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
passing items to paypal

Hi everyone.
I have built a website in php and everything is working ok, I have mysql, apache and php all behaving themselves, my problem lies with paypal not recieving all the items in my cart. If I add one item to my cart and check out to paypal there is no problem, if i add a second item and checkout it recieves the second but not the first in other words it doesnt seem to recieve (i think) all items held in that session.

please take a look at my code.

PHP: Select all

<?php 
session_start
(); 
 
//connect to database 
$mysqli mysqli_connect("me""me""me""me"); 
 
$display_block "<td align=\"center\"><h1>Your Shopping Cart</h1>"
 
//check for cart items based on user session id 
$get_cart_sql "SELECT st.id, si.item_title, si.item_price, st.sel_item_qty, st.sel_item_size, item_image, st.sel_item_color FROM store_shoppertrack AS st LEFT JOIN store_items AS si ON si.id = st.sel_item_id WHERE session_id = '".$_COOKIE["PHPSESSID"]."'"
$get_cart_res mysqli_query($mysqli$get_cart_sql) or die(mysqli_error($mysqli)); 
 
 
 
if (
mysqli_num_rows($get_cart_res) < 1) { 
    
//print message 
    
$display_block .= "<p>You have no items in your cart. 
    Please <a href=\"index.html\">continue to shop</a>!</p>"

} else { 
    
//get info and build cart display 
    
$display_block .= 
    <table border=\10 width=\"76%\"bgcolor=\"#FFCCFF\"<td align=\"center\"> 
    <tr> 
    <th>Image</th> 
    <th>Title</th> 
    <th>Size</th> 
    <th>Color</th> 
    <th>Price</th> 
    <th>Qty</th> 
    <th>Total Price</th> 
    <th>Action</th> 
    </tr>"

 
 
    while (
$cart_info mysqli_fetch_array($get_cart_res)) { 
 
           
$id $cart_info['id']; 
           
$item_title stripslashes($cart_info['item_title']); 
           
$item_price $cart_info['item_price']; 
           
$item_qty $cart_info['sel_item_qty']; 
           
$item_color $cart_info['sel_item_color']; 
           
$item_size $cart_info['sel_item_size']; 
        
$total_price sprintf("%.02f"$item_price $item_qty); 
        
$Sub_Total =  sprintf("%.02f"$total_price)+($Sub_Total); 
        
$item_image $cart_info['item_image']; 
 
//this i believe is the problem 
 
for($i=0$i count($get_cart_res); $i++){ 
$val $i 1
echo 
"<input type=\"hidden\" name=\"quantity_$val\" value=\"$item_qty\">"
echo 
"<input type=\"hidden\" name=\"item_name_$val\" value=\"$item_title\">"
echo 
"<input type=\"hidden\" name=\"amount_$val\" value=\"$item_price\">"
 
 

 
 
 

 
 
 
 
 
           
$display_block .= 
           <tr> 
        <td align=\"center\"><img src=\""
.$item_image."\"/></td> 
           <td align=\"center\">$item_title <br></td> 
           <td align=\"center\">$item_size <br></td> 
           <td align=\"center\">$item_color <br></td> 
           <td align=\"center\">£ $item_price <br></td> 
           <td align=\"center\">$item_qty <br></td> 
           <td align=\"center\">£ $total_price</td> 
           <td align=\"center\"><a href=\"removefromcart.php?id="
.$id."\">remove</a></td> 
           </tr>"

 
    } 
 
 

$display_block .= 
<tr> 
        <th><td align=\"right\"><strong>Sub Total</strong></th> 
        <td align=\"right\">£ $Sub_Total</td> 
        </td>"

    
$display_block .= "</table>"
    } 
 
?>
I think the for statement above may need tweaking but my tweaking has all tweaked out and I am now stumped and need help, lots of it.

Thanks in advance for any help or pointers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jun 9th, 2007, 04:57
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: passing items to paypal

I don't thin you need that extra for loop at all - I think the while loop is all you need, with an extra "$i" counter ... initialised to zero before the while loo, and ++'d within it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jun 9th, 2007, 08:41
Reputable Member
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: passing items to paypal

Thanks for the reply Grahame

I will give it a go and let you know how i get on.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jun 15th, 2007, 15:17
Reputable Member
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: passing items to paypal

Sorry for the delay but I have been playing around with what you suggested and after 5days I am now posting all my items and options with the click of one button. Its fantastic.

Many thanks for the help.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jun 16th, 2007, 01:34
Junior Member
Join Date: Jun 2006
Location: Here
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Re: passing items to paypal

Could you post the code to show how you achieved it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jun 16th, 2007, 10:13
Reputable Member
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: passing items to paypal

Hi there

Here is the complete code.

PHP: Select all

<?php
session_start
();
//connect to database
$mysqli mysqli_connect("me""me""me""me");
$display_block "<td align=\"center\"><h1>Your Shopping Cart</h1>";
//check for cart items based on user session id
$get_cart_sql "SELECT st.id, si.item_code, si.item_price,  st.sel_item_qty, st.sel_item_size, item_image, st.sel_item_color FROM store_shoppertrack AS st LEFT JOIN store_items AS si ON si.id = st.sel_item_id WHERE session_id = '".$_COOKIE["PHPSESSID"]."'";
$get_cart_res mysqli_query($mysqli$get_cart_sql) or die(mysqli_error($mysqli));
 
if (
mysqli_num_rows($get_cart_res) < 1) {
    
//print message
    
$display_block .= "<p>You have no items in your cart.
    Please <a href=\"index.html\">continue to shop</a>!</p>"
;
} else {
    
//get info and build cart display
    
$display_block .= "
    <table border=\10 width=\"76%\"bgcolor=\"#FFCCFF\"<td align=\"center\">
    <tr>
 <th>Image</th>
    <th>Title</th>
    <th>Size</th>
    <th>Color</th>
    <th>Price</th>
    <th>Qty</th>
    <th>Total Price</th>
    <th>Action</th>
    </tr>"
;
 
    while (
$cart_info mysqli_fetch_array($get_cart_res)) {
        
$id $cart_info['id'];
        
$item_title stripslashes($cart_info['item_code']);
        
$item_price $cart_info['item_price'];
 
        
$item_qty $cart_info['sel_item_qty'];
        
$item_color $cart_info['sel_item_color'];
        
$item_size $cart_info['sel_item_size'];
     
$total_price sprintf("%.02f"$item_price $item_qty);
  
$Sub_Total =  sprintf("%.02f"$total_price)+($Sub_Total);
  
$item_image $cart_info['item_image'];
 
 for(
$i=0$i count($get_cart_res); $i++){
$val ++;
 echo 
"<input type='hidden' name='item_name_$val'value='".$item_title."'>";
echo 
"<input type='hidden' name='amount_$val'value='".$item_price."'>";
 echo 
"<input type='hidden' name='quantity_$val'value='".$item_qty."'>";
 
echo 
"<input type='hidden' name='os1_$val' value='".$item_size."'>";
echo 
"<input type='hidden' name='on0_$val' value='".colour."'>";
echo 
"<input type='hidden' name='os0_$val' value='".$item_color."'>";
echo 
"<input type='hidden' name='on1_$val' value='".size."'>";
 
 
}
 
 
        
$display_block .= "
        <tr>
  <td align=\"center\"><img src=\""
.$item_image."\"/></td>
        <td align=\"center\">$item_title <br></td>
        <td align=\"center\">$item_size <br></td>
        <td align=\"center\">$item_color <br></td>
        <td align=\"center\">£ $item_price <br></td>
        <td align=\"center\">$item_qty <br></td>
        <td align=\"center\">£ $total_price</td>
        <td align=\"center\"><a href=\"removefromcart.php?id="
.$id."\">remove</a></td>
        </tr>"
;
 
    }
 
}
{
$display_block .= "
<tr>
  <th><td align=\"right\"><strong>Sub Total</strong></th>
  <td align=\"right\">£ $Sub_Total</td>
  </td>"
;
    
$display_block .= "</table>";
 }
?>
the paypal form goes before the start of the php code.

PHP: Select all

<html>
<
body>
<
form target"paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<
input type="hidden" name="cmd" value="_cart">
<
input type="hidden" name="upload" value="1">
<
input type="hidden" name="business" value ="me@me.co.uk">
<
input type="hidden" name="currency_code" value="GBP">
<
input type="hidden" name="shipping" value="4.95">
<
input type="hidden" name="shipping2" value="0.00">
<
form
you can put the submit to paypal code butoon anywhere you like.

I hope this helps.

Last edited by Daniel; Jun 16th, 2007 at 10:21. Reason: Added [php] tags :)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
cart, items, paypal

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Div not expanding to contain items inside snappy Web Page Design 6 Dec 6th, 2007 13:54
summerizing multiple items at once. Javilen Databases 1 Sep 20th, 2007 20:45
Animation for menu items David Blake Flash & Multimedia Forum 12 Jun 14th, 2007 00:54
PHP includes menu - problems with sub-items fallen_angel PHP Forum 3 Jan 19th, 2007 17:15
display mean and variance of purchased items chikenyd Other Programming Languages 1 Nov 4th, 2006 21:10


All times are GMT. The time now is 23:12.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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