Page 1 of 1

PHP Paypal problem

Posted: Tue Sep 14, 2004 4:26 am
by sgreen
Hi all.I've been messing around with this for days & can't get anywhere.

I want to send the total from my shopping cart to paypal but nothing seems to work.When you get to the paypal page it's just blank.I can't seem to get my paypal.php page to pick up the total.

This is the code from the checkout page below

Code: Select all

<?php
<?php
session_start();
include "header.inc.php"; 
$ttl_hal="Cart";
require "shop_menu.inc.php";

$arr_item=explode("|",$myshop);

?>

<table border=0 cellspacing=0 cellpadding=0 width=100%><tr><td class=black>
<!-- START CONTENTS -->
<script Language = JavaScript>

function input_verify(thisform)
{
	if (thisform.fnama.value=="")
        {
		alert("Please fill your name")
		thisform.fnama.focus()
		thisform.fnama.select()
		return false
	}

	if (thisform.falamat.value=="")
	{
		alert("Please fill your address")
		thisform.falamat.focus()
		thisform.falamat.select()
		return false
	}

	if (thisform.ftelpon.value=="")
	{
		alert("Please fill your phone number")
		thisform.ftelpon.focus()
		thisform.ftelpon.select()
		return false
	}

	if (thisform.falt_email.value=="")
	{
		alert("Please fill your email")
		thisform.falt_email.focus()
		thisform.falt_email.select()
		return false
	}


}

function setharga(){
   thisform.lbharga.value=thisform.selharga.options[selharga.selectedIndex].value;
}
</script>

<form method="POST" action="paypal.php" onsubmit="return input_verify(this);">
<h3>Your Order Items</h3>
<?php
$total=0;
$subtotal=0;
   if (!empty($myshop)){
      echo "<table border=0 cellspacing=1 cellpadding=4 class=black width=100%>";
      echo "<tr bgcolor=#CCCCCC><td><b>Picture</td><td><b>Name</td><td><b>Price<br>(conversion)</td><td><b>Qty</td><td><b>Subtotal(".$defcurr.")</td></tr>";
      for ($co=1; $co<count($arr_item); $co++){
         $item_picture="";
         $item_title="";
         $item_description="";
         $item_price="";
         $ro_shop=explode(":",$arr_item[$co]);
         $rs_item=@mysql_query("select * from shop_item where id='$ro_shop[0]'");
         $ada_item=@mysql_num_rows($rs_item);
         if ($ada_item>0){
            $item_picture=@mysql_result($rs_item,0,"picture");
            $item_title=@mysql_result($rs_item,0,"title");
            $item_description=@mysql_result($rs_item,0,"description");
            $item_curr=@mysql_result($rs_item,0,"curr");
            $item_price=@mysql_result($rs_item,0,"price");
            $item_disc=@mysql_result($rs_item,0,"discount");
         }
         echo "<tr>";
         echo "<td>";
         if ( (!empty($item_picture)) and (file_exists($item_picture)) ){
            echo "<img src='".$item_picture."' border=0 width=50 height=50>";
         }
         echo "</td>";
         echo "<td><b>".$item_title."</b>";
         echo "</td>";
         echo "<td align=right>";

         if (!empty($item_disc)){
            echo "<font color=#FF0000>".$item_curr." <strike>".number_format($item_price, 2)."</strike></font>";
            echo "<br><font color=#008080>Disc: ".$item_disc."%</font>";
            $item_price=$item_price - ($item_price*($item_disc/100));
            echo "<br>".$item_curr." ".number_format($item_price, 2);
         } else {
            echo $item_curr." ".number_format($item_price, 2);
         }

if ($defcurr<>$item_curr){
   $curr_from=@mysql_result(@mysql_query("select curr_value from shop_curr where curr_name='$item_curr'"),0,0);
   $curr_to=@mysql_result(@mysql_query("select curr_value from shop_curr where curr_name='$defcurr'"),0,0);
   $item_price=($item_price*$curr_to)/$curr_from;
//   echo "$curr_from | $curr_to";
   echo "<br>(".$defcurr." ". number_format($item_price,2).")";
}

         echo "</td>";
         echo "<td align=right>";
         echo $ro_shop[1];
         echo "</td>";
         $subtotal=$ro_shop[1]*$item_price;
         echo "<td align=right><b>".number_format($subtotal, 2)."</td>";
         echo "</tr>";
         $total=$total+$subtotal;
      }
      echo "<tr><td bgcolor=#CCCCCC colspan=4 align=right><b>T O T A L</td>";
      echo "<td bgcolor=#CCCCCC align=right><b>".number_format($total, 2)."</td></tr>";
      echo "</table>";
   } else {
      echo "<div align=center><h3><br>Your Cart is still empty,<br><a href='shop.php' class=black>Have a nice Shop</a>...!</h3></div>";
   }
?>

<h3>Delivery Address</h3>
<table border="0" cellpadding="2" cellspacing="0" class=black WIDTH=100%>
    <tr>
      <td align=right>Full Name:</td>
      <td><input type="text" name="fnama" size="20" class=ed></td>
    </tr>
    <tr>
      <td align=right>Address</td>
      <td><textarea rows="3" name="falamat" cols="27"  class=ed></textarea></td>
    </tr>
    <tr>
      <td align=right>Postal Code</td>
      <td><input type="text" name="fkodepos" size="9" class=ed></td>
    </tr>
    <tr>
      <td align=right>City</td>
      <td><input type="text" name="fkota" size="20"></td>
    </tr>
    <tr>
      <td align=right>Province</td>
      <td><input type="text" name="fpropinsi" size="20"></td>
    </tr>
    <tr>
      <td align=right>Phone</td>
      <td><input type="text" name="ftelpon" size="20" class=ed></td>
    </tr>
    <tr>
      <td align=right>Email</td>
      <td><input type="text" name="falt_email" size="20" class=ed>
      <input type="checkbox" name="ccmail" value="yes" checked><small>Send me Order Copy</small>
      </td>
    </tr>
    <tr>
      <td align=right>Your Note</td>
      <td><textarea rows="3" name="fcatatan" cols="27"  class=ed></textarea></td>
    </tr>

    <tr>
      <td align=center colspan=2 bgcolor=#CCCCCC>
        <input type="hidden" name="order" value="yes">
        <input type="button" value="« Back" name="btcancel" onclick=history.go(-1) class=but>
        <input type="submit" value="Finish »" name="btsubmit" class=but></td>
   
	</tr>
  </table>
</form>


<!-- END CONTENTS -->
</td></tr></table>
?>
End of code

I created a page called paypal.php & used the following code..

Code: Select all

<?php
<html>
<body>
<form name= "order" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_ext-enter"><br>
<input type="hidden" name="redirect_cmd" value="_xclick"><br>
<input type="hidden" name="return"
value = "http://<your site>/notify.php?status=T"><br>
<input type="hidden" name="cancel_return"
value = "http://<your site>/notify.php?status=F"><br>
<input type="hidden" name="business" value ="s@S">
<input type="hidden" name="item_name" value="your product">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="shipping2" value="0.00">
<!-- end of form -->
<?php
//get values from previous page
$item_price = $HTTP_GET_VARS['total'];
echo "<input type="hidden" name="total" value="$total"><br>\n";
?>
</form>

<script type="text/javascript" language="JavaScript">
//submit form
document.order.submit();
</script>
</body>
<html>
?>
Could somebody please point me in the right direction..

I've looked at the way paypal say to do it & they use 'amount' in their script & say you can't change it.What am I doing wrong?

Posted: Tue Sep 14, 2004 4:30 am
by mudkicker
please color your code...

two things

Posted: Tue Sep 14, 2004 4:35 am
by phpScott
1 before you upsett the mods go back and edit you post and put the PHP tags around your code.
Just below the subject line and on the left.

2 i think using HTTP_GET_VARS is the old way of doing things.
try

Code: Select all

<?php
$total=$REQUEST['total'];
//(not to worry about form methods)
//or
$total=$_POST['total'];
$total=$_GET['total'];
//(for post and get methods respectively)
?>

Posted: Tue Sep 14, 2004 10:09 am
by sgreen
I'm still getting nowhere.. All that I get is the paypal page & none of the info is passed from the cart.

The first part of the code above is the checkout page which when submitted goes to paypal.php & then to paypal.

total

Posted: Tue Sep 14, 2004 10:50 am
by phpScott
I did search through your cart page and didn't see where total is being stored in the form. maybe I am missing it?

try sending your form (temporarly of course) as method GET to see the string of info that is being passed to make sure that total is being passed.

phpscott

Posted: Wed Sep 15, 2004 8:54 am
by Pozor
hi,

just for verifikation:

Code: Select all

<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
It exist a way without the <pre> stuff but i cant remember, i saw it once.
Thats my way to debug a skript. As a tipp place the first <pre> at the beginning of your skript and the </pre> at the end, so you can easily
work with print_r at any place in your file, and it is still nice to read in the output.

greez Pozor

Posted: Wed Sep 15, 2004 9:47 am
by Getran
how about when they submit to the paypal.php page or w/e you store it in a flat file ? or DB (it creates a new for the user) then once you have sent the vars delete the file..or w/e