Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Cart Total variable to Paypal 2

Status
Not open for further replies.

WilliamMute

Programmer
Jan 4, 2006
117
Dear All,

I am not sure if I can ask this but, am trying to design a small web shop for my sister selling little bits and bobs. well I have put something together, with a shopping cart! My problem now is, that Paypal are not being of much help as I have been in communication with them for over 2 months now, beleive me. I simply just want a checkout button which I can echo the total value of the shopping cart to and post it to paypal. Problem, Paypal dont accept echoing a PHP variable into their form. As I havent done this before, is there any other way I can echo the cart total into paypals default html code they provide for the button? See paypal's recommended way below and my version of coding as well.

Code:
<form action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr"[/URL] method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myemail@yahoo.com">
<input type="hidden" name="item_name" value="item name">
<input type="hidden" name="item_number" value="001">
<input type="hidden" name="amount" value="<?php echo $amount ; ?>">
<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-BuyNowBF">
<input type="image" src="[URL unfurl="true"]https://www.paypal.com/en_US/i/btn/x-click-but23.gif"[/URL] border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="[URL unfurl="true"]https://www.paypal.com/en_GB/i/scr/pixel.gif"[/URL] width="1" height="1">
</form>

The code above was provided by paypal with the exception of the php echo part which I replaced with the defualt $0.00. etc. Any Help will be much appreciated please.

Thank you
 
You're not showing where you get the variable $amount from. What is the actual HTML for the value for your hidden input amount when it's displayed in the browser?

Lee
 
Thanks for your reply.

I get the amount from a query I perform. i.e

Code:
...
$result=mysql_query($sql)
or die ("Query Error: " . mysql_error());
$row=mysql_fetch_assoc($result);
$amount = "£" . number_format ( floatval($row['total']), 2, ".", ",");

That HTML for is provided by paypal, and it doesnt display on my php page, it simply a button, you click and the info is posted to paypal's site who decrypt it on their end. but the value that is supposed to display on their end is the total value of the shopping cart which I am echoing into the

Code:
<input type="hidden" name="amount" value="<?php echo $amount ; ?>">
 
Somehow the amount from your end has to get to their end. It gets there by being submitted from a web page on your site to their site. Correct? You have to send that amount to them, not some PHP code. Where is that value in the HTML on your site?

Lee
 
there is no html value, the value is echoed out via php in a php page.
 
Yes, I know that. Show the HTML output on the PHP page where the form element is, please. PHP is a server side scripting language that is used to build HTML pages with dynamic content. You need to look at the HTML content to see what's being written by PHP before it's passed to PayPal.

I've set up forms to submit to PayPal before, and know how it works.

Lee
 
Sorry, my mistake, I didn't quite understand your question.

here is the HTML view of the page I viewed the source code on the web and simply copied the neccessary part.

Code:
  <tr>
  <td  class="odd_row" colspan="6" align="center"><h4>YOUR SHOPPING BASKET SUMMARY </h4></td>
  
  </tr>

  <tr class="maintable">
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr class="SubHeadings">
        <td>Image</td>
		<td> Qty</td>
		<td>Item Name</td>
        <td>Dimension </td>

        <td>Product Code </td>
        <td>Price</td>
        
      </tr>
      
	  
			  <style>
.even_row {background-color:#FFFFFF;}
.odd_row {background:url(../images/mysql_bg.jpg);}
/*.odd_row {background-color:#00CCFF;} */
</style>
	  
	     <tr class= odd_row><br/><td width="15%">
<a href="[URL unfurl="true"]http://www.spring.net/single_item.php?id=34">[/URL]
<img src="products/WN002.jpg" alt="Product in your Basket" width="30" height="25"></a>
</td><td width=10%><br/>1</td><td width=25%><br/>Wedding Necklace</td><td width=20%><br/>18 inches</td><td width=20%><br/>WN002</td><td width=10%><br/>£69.99</td></tr><tr class= even_row><br/><td width="15%">

<a href="[URL unfurl="true"]http://www.spring.net/single_item.php?id=34">[/URL]
<img src="products/WN002.jpg" alt="Product in your Basket" width="30" height="25"></a>
</td><td width=10%><br/>1</td><td width=25%><br/>Wedding Necklace</td><td width=20%><br/>18 inches</td><td width=20%><br/>WN002</td><td width=10%><br/>£69.99</td></tr>	  
	  
	
	  <tr>
        <td colspan="6" class="LoopRowsQuery">
		
		
	</td>
      </tr>
	
		&nbsp;</td>

        </tr>
		
		
      <tr>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  <td height="10" class="LoopRowsQuery" colspan="" align="left">Subtotal:</td>
        <td height="10" class="LoopRowsQuery" colspan="2" align="right">£139.98</td>
      </tr>

      <tr>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	    <td height="10" class="LoopRowsQuery2" colspan="" align="left">Total:</td>
        <td class="LoopRowsQuery2" colspan="2" align="right"><strong>£139.98</strong></td>
        
      </tr>
      <tr>

        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="mainnav">
		







<form action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr"[/URL] method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="dupsytt@yahoo.com">
<input type="hidden" name="item_name" value="item name">
<input type="hidden" name="item_number" value="001">
<input type="hidden" name="amount" value="£139.98">
<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-BuyNowBF">
<input type="image" src="[URL unfurl="true"]https://www.paypal.com/en_US/i/btn/x-click-but23.gif"[/URL] border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="[URL unfurl="true"]https://www.paypal.com/en_GB/i/scr/pixel.gif"[/URL] width="1" height="1">
</form>
		
		
		
		[ Pay for Items ] </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>

I hope this is what you are looking for. Thanks so much for your help.
 
I would guess that the pound sign in your amount field is causing the problem. All the examples in the PayPal documentation show either integer or decimal values, but no currency characters.

Lee
 
The pound sign is not there normaily, its just a html manual input that I put there. i.e I just said echo '£'$amount; something like that. thats why the source just displayed that.
 
Remove it then.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
If you don't provide your real code, you won't get a real answer to your question.

Lee
 
Guys you are geniouses! if there is such word. what was causing the problem all along was that pound £ sign... DOUGH I should have notice that! Thanks so much for your contribution and for spoting it out!


Cheers guys...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top