I was hoping to find someone with shopping cart and paypal experience. I'm learning how to integrate paypal with my website, but I'm having touble getting logging in my mock buyer paypal account from the paypal checkout page. My payment button on my site seems to work fine and takes me to the paypal checkout page and displays all the correct information, but when I try to login with the buyer account i created in the sandbox it says I'm using the wrong email or password to log in. For my site I'm using the upload cmd which I think is up is causing the problem, because when I try out a test example that just uses the normal cmd value and _xclick I can log into my paypal account fine. Here is my code for my cart that has the paypal button. I use a php variable $pp_checkout_btn to gather all the info for the paypal button.

<?php

session_start(); // Start session first thing in script
// Script Error Reporting

if (!isset($_SESSION["username"])) {
    header("location: user_login.php");
    exit();
}

error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database
include "connect_to_mysql.php";
?>
<?php


// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
        // Put stored session variables into local php variable
    $userid = $_SESSION['id'];
    $username = $_SESSION['username'];
        $toplinks =  $username .  '&bull;
        <a href="index.php">Home</a> &bull;
        <a href="member_account.php">Account</a> &bull;
        <a href="logout.php">Log Out</a> &bull;
        <a href="cart.php">Cart</a>';
} else {
        $toplinks = '<a href="user_register.php">Register</a> &bull; <a href="user_login.php">Login</a>';
}

?>
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 1 (if user attempts to add something to the cart from the product page)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['pid'])) {
    $pid = $_POST['pid'];
        $wasFound = false;
        $i = 0;
        // If the cart session variable is not set or cart array is empty
        if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
            // RUN IF THE CART IS EMPTY OR NOT SET
                $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1));
        } else {
                // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
                foreach ($_SESSION["cart_array"] as $each_item) {
                      $i++;
                      while (list($key, $value) = each($each_item)) {
                                  if ($key == "item_id" && $value == $pid) {
                                          // That item is in cart already so let's adjust its quantity using array_splice()
                                             array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
                                          $wasFound = true;
                                  } // close if condition
                      } // close while loop
               } // close foreach loop
                   if ($wasFound == false) {
                           array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1));
                   }
        }
        header("location: cart.php");
    exit();
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 2 (if user chooses to empty their shopping cart)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
    unset($_SESSION["cart_array"]);
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 3 (if user chooses to adjust item quantity)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") {
    // execute some code
        $item_to_adjust = $_POST['item_to_adjust'];
        $quantity = $_POST['quantity'];
        $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers
        if ($quantity >= 100) { $quantity = 99; }
        if ($quantity < 1) { $quantity = 1; }
        if ($quantity == "") { $quantity = 1; }
        $i = 0;
        foreach ($_SESSION["cart_array"] as $each_item) {
                      $i++;
                      while (list($key, $value) = each($each_item)) {
                                  if ($key == "item_id" && $value == $item_to_adjust) {
                                          // That item is in cart already so let's adjust its quantity using array_splice()
                                          array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity)));
                                  } // close if condition
                      } // close while loop
        } // close foreach loop
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 4 (if user wants to remove an item from cart)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") {
    // Access the array and run code to remove that array index
        $key_to_remove = $_POST['index_to_remove'];
        if (count($_SESSION["cart_array"]) <= 1) {
                unset($_SESSION["cart_array"]);
        } else {
                unset($_SESSION["cart_array"]["$key_to_remove"]);
                sort($_SESSION["cart_array"]);
        }
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 5  (render the cart for the user to view on the page)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$product_id_array = '';
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
    $cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
        // Start PayPal Checkout Button
        $pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"  accept-charset="utf-8">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="business" value="pwang@sofpower.com">';
        // Start the For Each loop
        $i = 0;
    foreach ($_SESSION["cart_array"] as $each_item) {
                $item_id = $each_item['item_id'];
                $query = "SELECT * FROM product WHERE id='$item_id' LIMIT 1";
                $result = $db_obj->query($query);
        if($db_obj->error) exit ($db_obj->error);
                //$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
                while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
                        $product_name = $row["product_name"];
                        $price = $row["price"];
                        $details = $row["details"];
                }
                $pricetotal = $price * $each_item['quantity'];
                $cartTotal = $pricetotal + $cartTotal;
                $_SESSION["cart"] = $cartTotal;
                setlocale(LC_MONETARY, "en_US");
        //$pricetotal = money_format("%10.2n", $pricetotal);
                // Dynamic Checkout Btn Assembly
                $x = $i + 1;
                $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '">
        <input type="hidden" name="amount_' . $x . '" value="' . $price . '">
        <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '">  ';
                 // Create the product array variable
                $product_id_array .= "$item_id-".$each_item['quantity'].",";
                // Dynamic table row assembly
                $cartOutput .= "<tr>";
                $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>';
                $cartOutput .= '<td>' . $details . '</td>';
                $cartOutput .= '<td>$' . $price . '</td>';
                $cartOutput .= '<td><form action="cart.php" method="post">
                <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
                <input name="adjustBtn' . $item_id . '" type="submit" value="change" />
                <input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
                </form></td>';
                //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
                $cartOutput .= '<td>' . $pricetotal . '</td>';
                $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
                $cartOutput .= '</tr>';
                $i++;
    }
        setlocale(LC_MONETARY, "en_US");
    //$cartTotal = money_format("%10.2n", $cartTotal);
        $cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : ".$cartTotal." USD</div>";

  // Finish the Paypal Checkout Btn
        $pp_checkout_btn .= '

        <input type="hidden" name="return" value="http://webdev.cs.kent.edu/~jfunchio/wp2/HW2/checkout_complete.php">
        <input type="hidden" name="cancel_return" value="http://webdev.cs.kent.edu/~jfunchio/wp2/HW2/paypal_cancel.php">
        <input type="image" src="https://www.paypal.com/images/x-click-butcc.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">
        </form>';
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Your Cart</title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
  <?php //include_once("template_header.php");
        echo $toplinks;
  ?>
  <div id="pageContent">
    <div style="margin:24px; text-align:left;">

    <br />
    <table width="100%" border="1" cellspacing="0" cellpadding="6">
      <tr>
        <td width="18%" bgcolor="#C5DFFA"><strong>Product</strong></td>
        <td width="45%" bgcolor="#C5DFFA"><strong>Product Description</strong></td>
        <td width="10%" bgcolor="#C5DFFA"><strong>Unit Price</strong></td>
         <td width="9%" bgcolor="#C5DFFA"><strong>Quantity</strong></td>
        <td width="9%" bgcolor="#C5DFFA"><strong>Total</strong></td>
        <td width="9%" bgcolor="#C5DFFA"><strong>Remove</strong></td>
      </tr>
     <?php echo $cartOutput; ?>
     <!-- <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr> -->
    </table>
    <?php echo $cartTotal; ?>
    <br />
    <a href="checkout.php">Checkout</a>
    <br />
<br />
<?php echo $pp_checkout_btn; ?>
    <br />
    <br />
    <a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a>
    </div>
   <br />
  </div>
  <?php include_once("template_footer.php");?>
</div>
</body>
</html>

Here the code for the example that works

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8"/>
<title>SuperStore.Com</title></head>
<body style="margin: 50px">
<h2>Purchase Our Product Online</h2>
<p><img src="hammer.jpeg" alt="Hammer" style="vertical-align: middle" />
&nbsp;&nbsp;&nbsp;Hammer for $4.49.</p>

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" accept-charset="utf-8">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="jfunchio@kent.edu" />
<input type="hidden" name="item_name" value="Hammer" />
<input type="hidden" name="amount" value="4.49" />
<input id="tt" type="hidden" name="return" value="success return URL" />
<input id="ff" type="hidden" name="cancel_return" value="failure return URL" />
<!-- company logo for PayPal page -->
<input type="hidden" name="image_url"
       value="http://www.sofpower.com/images/sofppal.gif" />
<input type="hidden" name="cn" value="Special Instructions (optional)" />
<table style="background-color: #ddffee">
<tr><td>&nbsp;</td></tr>
<tr><td>Customer Full Name</td><td>
<input type="text" name="cnm"  size="30" maxlength="50" /></td></tr>
<tr><td><input type="hidden" name="on0" value="customer email address" />
Customer email</td>
<td><input type="text" name="os0" size="30" maxlength="100" /></td></tr>
<tr><td><input type="hidden" name="on1" value="customer institution" />
Customer institution</td>
<td><input type="text" name="os1" size="30" maxlength="100" /></td></tr>
<tr><td>&nbsp;</td></tr>
</table><br />
<input type="image" src="https://www.paypal.com/images/x-click-butcc.gif"
border="0" name="submit"
alt="Make payments with PayPal - it's fast, free and secure!" />
</form>
<p>When payment has been received, we will
also send a confirmation to you by email.<br />
After ordering, if you need to get in touch with us, please
send email to<br />
<tt>customer-service@superstore.com</tt>.</p>
<pre>

</pre>
</body></html>
Member Avatar for LastMitch

I'm learning how to integrate paypal with my website, but I'm having touble getting logging in my mock buyer paypal account from the paypal checkout page.

If you are having trouble logging in the account most likely you integrated it incorrectly. Even it is a sandbox (demo) account. You can still reset your password from that account.

http://www.evoluted.net/thinktank/web-development/paypal-php-integration

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.