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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Help, sending data to database ... please...

    Hi

    I really am trying to learn this without asking for help, but there's a tiny bit of code that I don't know.
    I have successfully used Paypal ipn to a listener file and that file shows me the all the transaction details as a txt, so I know that's ok.
    I just need to get that data sent to my database, which I have set up already.

    Here's the code, you'll see at the end I've tried to write what to do next "insert" in to my database, can anyone help? please...

    PHP Code:
    <?php
    /**
     * Paypal IPN Class (Testing Only)
     *
     * @author        JREAM
     * @link        http://jream.com
     * @copyright        2011 Jesse Boyer (contact@jream.com)
     * @license        GNU General Public License 3 (http://www.gnu.org/licenses/)
     *
     * This program is free software; you can redistribute it and/or modify it
     * under the terms of the GNU General Public License as published by the
     * Free Software Foundation; either version 3 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     * GNU General Public License for more details:
     * http://www.gnu.org/licenses/
     */
     
    class Paypal_IPN
    {
        
    /** @var string $_url The paypal url to go to through cURL
        private $_url;

        /**
        * @param string $mode 'live' or 'sandbox' 
        */
        
    public function __construct($mode 'live')
        {
            if (
    $mode == 'live')
            
    $this->_url 'https://www.paypal.com/cgi-bin/webscr';
            
            else
            
    $this->_url 'https://www.sandbox.paypal.com/cgi-bin/webscr';
        }

        public function 
    run()
        {
            
    $postFields 'cmd=_notify-validate';
            
            foreach(
    $_POST as $key => $value)
            {
                
    $postFields .= "&$key=".urlencode($value);
            }
        
            
    $ch curl_init();

            
    curl_setopt_array($ch, array(
                
    CURLOPT_URL => $this->_url,
                
    CURLOPT_RETURNTRANSFER => true,
                
    CURLOPT_SSL_VERIFYPEER => false,
                
    CURLOPT_POST => true,
                
    CURLOPT_POSTFIELDS => $postFields
            
    ));
            
            
    $result curl_exec($ch);
            
    curl_close($ch);
            
            
            
    //
            
    if ($result == 'VERIFIED') {
                
    //$this->db->insert();
                
            
    } else {
            }
            
        }
    }

  • #2
    New Coder
    Join Date
    Feb 2013
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I've added more so it sends to the database but doesn't work.

    The script in the post above works and sends a verified log to a txt so I know paypal's ipn sends and recieve's it fine, it's just the part of getting it in the database that has stuck, any help... small donation offered, been stuck on this for a week.

    This script below replaces
    PHP Code:
    if ($result == 'VERIFIED') { 
                
    //$this->db->insert(); 
    PHP Code:
            if ($_POST['payment_status'] == 'completed')

                
    //$this->db->insert();
            
             
    $db_host "213.171.2xxxxx"
    // Place the username for the MySQL database here 
    $db_username "xxxxx";  
    // Place the password for the MySQL database here 
    $db_pass "xxxxxx";  
    // Place the name for the MySQL database here 
    $db_name "xxxxx"

    mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
    mysql_select_db("$db_name") or die ("no database");

    mysql_query("INSERT INTO customers (payer_email) VALUES ('$payer_email'");
    }
    }
            
            
    else if (
    strcmp ($res"INVALID") == 0) {
    //
    // 
    //
    $mail_To "hellcatchris@hotmail.co.uk";
    $mail_Subject "PayPal - Invalid IPN ";
    $mail_Body "We have had an INVALID response. \n\nThe transaction ID number is: $txn_id \n\n username = $username business=$receiver_email";
    mail($mail_To$mail_Subject$mail_Body);
    }
    //end of while
    mysql_close($dbhandle);
    fclose ($fp);
    }
    ?> 

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    I think people were reluctant to help you originally given that the only code you were offering up was
    PHP Code:
    //$this->db->insert(); 
    Given you have put some effort in I want to help you, but need more information. Are there any errors outputted from die syntax?? Make sure error reporting is on, espically if this is a production server on-line as it may be hiding valuable information.

    Assuming you are getting no die() connection errors place die() on the end of the query to see if you are getting an error, you will get one because your syntax is incorrect..

    PHP Code:
    mysql_query("INSERT INTO customers (payer_email) VALUES ('$payer_email'"); 
    Should have a closing bracket for value

    PHP Code:
    mysql_query("INSERT INTO customers (payer_email) VALUES ('$payer_email') ") or die("Error at insert".mysql_error()); 
    Obviously remove mysql_error() once all working


  •  

    Posting Permissions

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