www.webdeveloper.com
Results 1 to 2 of 2

Thread: paypal pdt sql php int

  1. #1
    Join Date
    Sep 2012
    Posts
    1

    paypal pdt sql php int

    So here is the issue, I am trying to do a PDT and grab the basic info and post to sql, more importantly a custom variable aswell. Its an integer, called "lvel" also "apv" into users under "user_level" and "approved" but it will put the value if i manually set it to "1,2,3..etc" but if i use the $apv or $lvel .. it wont insert it.. any ideas ? would be amazing. warning.. very messy from trials..
    Code:
    <?php
    session_start();
    $sid = session_id();
    include 'dbc.php';
    ?>
    <?php
    
    $pp_hostname = "www.sandbox.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox
    
    
    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-synch';
    
    $tx_token = $_GET['tx'];
    $auth_token = "jXq6nVTQxMtp6_3K0TPHqkUJ5q56aMmSVOD1ypmY0GKX-EXNutq_H1CaAyC";
    $req .= "&tx=$tx_token&at=$auth_token";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    //set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
    //if your server does not bundled with default verisign certificates.
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
    $res = curl_exec($ch);
    curl_close($ch);
    
    if(!$res){
        //HTTP ERROR
    }else{
         // parse the data
        $lines = explode("\n", $res);
        $keyarray = array();
        if (strcmp ($lines[0], "SUCCESS") == 0) {
            for ($i=1; $i<count($lines);$i++){
            list($key,$val) = explode("=", $lines[$i]);
            $keyarray[urldecode($key)] = urldecode($val);
        }
        // check the payment_status is Completed
        // check that txn_id has not been previously processed
        // check that receiver_email is your Primary PayPal email
        // check that payment_amount/payment_currency are correct
        // process payment
        $firstname = $keyarray['first_name'];
        $lastname = $keyarray['last_name'];
        $itemname = $keyarray['item_name'];
        $amount = $keyarray['payment_gross'];
    
        echo ("<p><h3>Thank you for your purchase!</h3></p>");
    
        echo ("<b>Payment Details</b><br>\n");
        echo ("<li>Name: $firstname $lastname</li>\n");
        echo ("<li>Item: $itemname</li>\n");
        echo ("<li>Amount: $amount</li>\n");
        //echo ('$sid');
        }
    }echo("$amount");
        $apv = '1';
        if($amount == "4.00"){
            $level = '1';
            $sub =1;
        }
        if($amount == "6.00"){
            $lvel = '2';
            $sub =1;
        }
        if($amount == "10.00"){
            $lvel = '3';
            $sub =1;
        }
        if($amount == "14.00"){
            $lvel = '4';
            $sub =1;
        }
        if($amount == "20.00"){
            $lvel = '5';
            $sub =1;
        }
        if($amount == "25.00"){
            $lvel = '6';
            $sub =1;
        }
        if($amount == "30.00"){
            $lvel = '7';
            $sub =1;
        }
        if($amount == "40.00"){
            $lvel = '8';
            $sub =1;
        }
        if($amount == "12.00"){
            $level = '1';
            $sub =2;
        }
        if($amount == "22.00"){
            $lvel = '2';
            $sub =2;
        }
        if($amount == "32.00"){
            $lvel = '3';
            $sub =2;
        }
        if($amount == "42.00"){
            $lvel = '4';
            $sub =2;
        }
        if($amount == "66.00"){
            $lvel = '5';
            $sub =2;
        }
        if($amount == "80.00"){
            $lvel = '6';
            $sub =2;
        }
        if($amount == "95.00"){
            $lvel = '7';
            $sub =2;
        }
        if($amount == "125.00"){
            $lvel = '8';
            $sub =2;
        }
    
    
    
    
    mysql_query("update users set approved='$apv' where sid='$sid'");
    mysql_query("update users set user_level='$lvel' where sid='$sid'");
    
        //else if (strcmp ($lines[0], "FAIL") == 0) {
            // log for manual investigation
       // }
    
    
    
    
    ?>
    <?php 
    $apv1 = '1';
    mysql_query("update users set approved='$apv1' where sid='$sid'");
    ?>
    Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br> You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>

  2. #2
    Join Date
    Sep 2012
    Posts
    3
    Change your query to use the string concat operators to add them. ie. mysql_query("update users set approved='".$apv."' where sid='".$sid"."'");

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles