Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    49
    Thanks
    14
    Thanked 0 Times in 0 Posts

    paypal shopping cart wont load.

    hi all, been folllowing the phpacademy mini shopping cart tutorial and i've almost finished, gone to test it and it just takes me to a paypal page rather than the paypal cart page. here is my code, hope someone can help.

    PHP Code:
    <?php
    session_start
    ();
    $page 'index.php' ;

    mysql_connect('localhost','tjwebsol_cart','HIDDEN') or die(mysql_error());
    mysql_select_db('tjwebsol_cart') or die(mysql_error());

    if (isset(
    $_GET['add'])) {
        
    $quantity mysql_query('SELECT id, quantity FROM products WHERE id='.mysql_real_escape_string((int)$_GET['add']));
        while (
    $quantity_row mysql_fetch_assoc($quantity)) {
            if (
    $quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) {
                
    $_SESSION['cart_'.(int)$_GET['add']]+='1';
            }
        
        }
        
    header('Location: '.$page);
        
    }

    if (isset(
    $_GET['remove'])) {
        
    $_SESSION['cart_'.(int)$_GET['remove']]--;
        
    header('Location: '.$page);
    }
    if (isset(
    $_GET['delete'])) {
        
    $_SESSION['cart_'.(int)$_GET['delete']]='0';
        
    header('Location: '.$page);
    }



    function 
    products() {
        
    $get mysql_query('SELECT * FROM products WHERE quantity > 0 ORDER BY id DESC');
        if (
    mysql_num_rows($get)==) {
        echo 
    "There are no products to display.";
        }
        else
        {
        while (
    $get_row mysql_fetch_assoc($get)) {
            echo 
    '<p>'.$get_row['name'].'<br />'.$get_row['description'].'<br />&pound;'.number_format($get_row['price'] ,2).' <a href="cart.php?add='.$get_row['id'].'">Add</a></p>';
            }
        }
        
    }

    function 
    paypal_items() {
        
    $num 0;
        foreach(
    $_SESSION as $name => $value) {
            if(
    $value!=0) {
                if (
    substr($name05)=='cart_') {
                    
    $id substr($name5strlen($name)-5);
                    
    $get mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
                    while (
    $get_row mysql_fetch_assoc($get)) {
                    
    $num++;
                    echo 
    '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">';
                    echo 
    '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">';
                    echo 
    '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">';
                    echo 
    '<input type="hidden" name="shipping_'.$num.'" value="2.50">';
                    echo 
    '<input type="hidden" name="shipping2_'.$num.'" value="1.00">';
                    echo 
    '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">';
                    }
                }
            }
        }
    }

    function 
    cart() {
        foreach(
    $_SESSION as $name => $value) {
        if (
    $value>0) {
            if (
    substr($name05)=='cart_') {
                
    $id substr($name5, (strlen($name)-5));
                
    $get mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
                while (
    $get_row mysql_fetch_assoc($get)) {
                
    $sub $get_row['price']*$value;
                    echo 
    $get_row['name'].' x '.$value.' @ &pound;'.number_format($get_row['price'], 2).' = &pound;'.number_format($sub2).'<a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />';
                }
            }
            
    $total += $sub;
        }
        }
            if (
    $total==0) {
                echo 
    "Your cart is empty.";
            }
            else {
                echo 
    '<p>Total: &pound;'.number_format($total2).'</p>';
                
    ?>
                <p>
                <form 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="timtoday967@hotmail.co.uk">
                <?php paypal_items(); ?>
                <input type="hidden" name="currency_code" value="GBP">
                <input type="hidden" name="amount" value="<?php echo $total?>">
                <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
                </form>
                </p>
                <?php
            
    }
    }


    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Not sure what the post means ...
    What's the difference between "paypal page", and the "paypal cart page" ...
    Are those different scripts? ??

  • #3
    New Coder
    Join Date
    Apr 2011
    Posts
    49
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    Not sure what the post means ...
    What's the difference between "paypal page", and the "paypal cart page" ...
    Are those different scripts? ??
    Sorry I probably should have explained my problem a bit better. Basicly what should happen is once the user has added some items to there cart and clicked the paypal checkout button it should open a page on the paypal website that shows the users cart and details about all the items e.g name, quantity price etc and then they should be able to pay from there by entering their details. But at the moment all it does is show the web page https://www.paypal.com/cgi-bin/webscr rather than the cart with the users order.

  • #4
    New Coder
    Join Date
    Jan 2010
    Location
    Birmingham, MI
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Code:
     <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    Without knowing more about which PayPal API you are using, and spending a bit more time looking at PayPal and your script, The "action" attribute in form is what determines where the script goes. If the page that is loading is wrong, change the action attribute to the page you want.

    What is possibly happening though, is that it is not taking the person to the wrong page at all. It is taking them to the correct page, but they are not logged in so it redirects them to the login page. You aren't trying to checkout though at this point are you? Just trying to add to a PayPal shopping cart. This is not really likely what is happening. I haven't really used that API before. I have used Website Payments Pro. Sorry I can't be of more help.

  • #5
    New Coder
    Join Date
    Apr 2011
    Posts
    49
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by JamesOxford View Post
    Code:
     <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    Without knowing more about which PayPal API you are using, and spending a bit more time looking at PayPal and your script, The "action" attribute in form is what determines where the script goes. If the page that is loading is wrong, change the action attribute to the page you want.

    What is possibly happening though, is that it is not taking the person to the wrong page at all. It is taking them to the correct page, but they are not logged in so it redirects them to the login page. You aren't trying to checkout though at this point are you? Just trying to add to a PayPal shopping cart. This is not really likely what is happening. I haven't really used that API before. I have used Website Payments Pro. Sorry I can't be of more help.
    I'll try and do some more research on the paypal api today, not really sure which one it uses as I was following a video tutorial. I'll keep trying and hopefully something will fix it.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,537
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Tim,
    Be sure to create a free Sandbox account to set up a fake seller and fake buyer.
    This will allow you to test your site/scripts in a real PayPal environment. You simulate
    a complete transaction using a test credit card. Once you get out all of the bugs,
    you simply redirect your API and PayPal account to the REAL PayPal site.

    https://developer.paypal.com/

    They also have many script examples and documentation.


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •