Jump to content

Recommended Posts

Hi Guys,

 

i'm wondering if this is possible:

 

code:

 

<?php

// FORM END ------------------------------------------------------------------------- //

print("<form action=\"https://www.sandbox.paypal.com/cgi-bin/webscr\" method=\"post\" id=\"payPalForm\">");
print("<table width=\"80%\" border=\"0\" cellspacing=\"0\" cellpadding=\"6\" style=\"border:#d9dce2 1px solid;\">\n");
print("<tr>");
print("<td colspan=\"5\" bgcolor=\"#ecedf0\" align=\"left\"><b>Order Details</b></td>");
print("</tr>");
print("<tr>");
print("<td bgcolor=\"#ecedf0\" align=\"center\"><b>Product Name</b></td><td bgcolor=\"#ecedf0\" align=\"center\"><b>Price</b></td><td bgcolor=\"#ecedf0\" align=\"center\"><b>Quantity</b></td><td bgcolor=\"#ecedf0\" align=\"center\"><b>Sum-Total</b></td>");
print("</tr>");
print("<tr>"); 

// while loop the details //
$session_id = $_SESSION['id'];
$queryorder = "SELECT * FROM `fcp_orders` WHERE `customer_id`='$session_id'";
$resultsorder = mysql_query($queryorder);

// loop //
while($row = mysql_fetch_array($resultsorder))
{

$pid = $row['product_id'];
$quantity = $row['quantity'];
$quantity_total = $row['quantity_total'];

// get the name of the product //
$queryproduct = "SELECT * FROM `fcp_products` WHERE `id`='$pid'";
$resultsproduct = mysql_query($queryproduct);
$rows = mysql_fetch_array($resultsproduct);
// the name in a var //
$product_name = $rows['product_name'];
$product_price = $rows['product_price'];

// get the total price due //
$queryprice = "SELECT SUM(quantity_total) as `total` FROM `fcp_orders` WHERE `customer_id`='$session_id'";
$resultsprice = mysql_query($queryprice);
$r = mysql_fetch_array($resultsprice);

// vars //
$total_due = $r['total'];

// shipping //
$shipping_costs = 10;

// total owed //
$total_owed = $total_due + $shipping_costs;

// number format //
$total_owed = number_format($total_owed, 2);

// hidden field with the total //
print("<input type=\"hidden\" name=\"hidden_quantity\" value=\"$total_owed\">");

print("<td align=\"center\">$product_name</td><td align=\"center\">£$product_price</td><td align=\"center\">$quantity</td><td align=\"center\">£$quantity_total</td></tr>");

## PAYPAL VARS ##
print('<input type="hidden" name="item_number" value="1">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="no_note" value="1">
        <input type="hidden" name="business" value="graham_1203854116_biz@hotmail.com">
        <input type="hidden" name="currency_code" value="GBP">');
        
print("<input type=\"hidden\" name=\"item_number\" value=\"1\">\n");
print("<input type=\"hidden\" name=\"item_name\" value=\"$product_name\">\n");
print("<input type=\"hidden\" name=\"amount\" value=\"$product_price\">\n");
print("<input type=\"hidden\" name=\"quantity\" value=\"$quantity\">\n\n");
## PAYPAL VARS ##

}

print("<tr><td style=\"border-top:#d9dce2 1px solid;\" colspan=\"3\" align=\"right\"><b>Shipping -</b></td><td bgcolor=\"#ecedf0\" style=\"border-top:#000000 1px solid; border-left:#000000 1px solid;border-right:#000000 1px solid;\ align=\"center\"><b>£$shipping_costs</b></td></tr></tr><td style=\"border-top:#d9dce2 1px solid;\"> </td><td style=\"border-top:#d9dce2 1px solid;\" align=\"right\" colspan=\"2\"><b>Total -</b></td><td bgcolor=\"yellow\" style=\"border-left:#000000 1px solid;border-right:#000000 1px solid; border-bottom:#000000 1px solid;\"><b>£ $total_owed</b></td>");

// end table //
print("</table>");
print("<br />");

// FORM END ------------------------------------------------------------------------- //

?>

 

this part here mainly:

 

<?php
print("<input type=\"hidden\" name=\"item_number\" value=\"1\">\n");
print("<input type=\"hidden\" name=\"item_name\" value=\"$product_name\">\n");
print("<input type=\"hidden\" name=\"amount\" value=\"$product_price\">\n");
print("<input type=\"hidden\" name=\"quantity\" value=\"$quantity\">\n\n");
?>

 

i really need the item number to increment (and basically all these 4 fields) so when i send it over to paypal, it treats them all individually, right now its setup it will only send 1 item to them, is there a way to increment the fields while in this loop already?

 

cheers guys

 

Graham

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/93223-incrementing-a-field-in-a-while-loop/
Share on other sites

Incrementing the item number is easy:

 

<?php

$numberOfItems = 10;
for ($i = 1; $i<=$numberOfItems; $i++) {

    print("<input type=\"hidden\" name=\"item_number\" value=\"{$i}\">\n");
    print("<input type=\"hidden\" name=\"item_name\" value=\"$product_name\">\n");
    print("<input type=\"hidden\" name=\"amount\" value=\"$product_price\">\n");
    print("<input type=\"hidden\" name=\"quantity\" value=\"$quantity\">\n\n");

}

 

However, you need to determine how PayPal expects the other fields to be formatted so the Quantities, Names, and Amounts are all associated with the appropriate items and implement that as well. Without any changes only the last Quantity, Name & Amount would be passed.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.