Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2011, 11:29 PM   PM User | #1
eberdome
Regular Coder

 
Join Date: Dec 2010
Location: California
Posts: 193
Thanks: 28
Thanked 8 Times in 8 Posts
eberdome is an unknown quantity at this point
having trouble updating a variable to database + PayPal Integration

Hello Everyone,

I am pretty new to the forums and was curious if i could get some help here. Basically, in a nutshell, i have PayPal integrated into my website. I will use this to collect money from clients. when a client logs into his/her account they see their balance (which is pulled from the database to correspond with the user that's logged-in). Now, everytime a payment is submitted a notify_url is contacted after payment has been verified, that notify_url is the code written below. What I am trying to execute here is when this notify_url is called the current balance is reduced from the amount paid through paypal.

In the second If condition, you will see that the word success is being entered into the paypal.txt file, which is working perfectly fine. Now, you will also see the variable
PHP Code:
$update_balance
which is suppose to update the original balance with the balance paid through PayPal

BUT IT'S NOT!! WHY?? LOL

Thank You in advance!

PHP Code:
<?php
ob_start
();

session_start();

include_once (
'/home/rdewebde/public_html/includes/paypal.php');

$myPaypal = new Paypal();

$myPaypal->ipnLog TRUE;
        
include_once 
"/home/rdewebde/public_html/includes/_config.php";

$username "".$_SESSION['username']."";

$users_data mysql_query("SELECT * FROM `members` WHERE `username`='".$username."'");

$user_info mysql_fetch_array($users_data);

$current_amount $user_info['balance'];
     
$deduct_amount $myPaypal->ipnData['payment_gross'];

$new_amount $current_amount $deduct_amount;

$update_balance mysql_query("UPDATE `members` SET `balance` = '$new_amount' WHERE `username` = '".$username."'");

if (
$myPaypal->validateIpn()) {

    if (
$myPaypal->ipnData['payment_status'] == 'Completed') {

         
$update_balance;  

         
file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt''SUCCESS');

            

    }

else { 
file_put_contents('/home/rdewebde/public_html/lounge/paypal.txt'"FAILURE\n\n" $myPaypal->ipnData); }

   }

?>

Last edited by eberdome; 01-29-2011 at 11:45 PM..
eberdome is offline   Reply With Quote
Old 01-30-2011, 12:32 AM   PM User | #2
macleodjb
Regular Coder

 
Join Date: Apr 2007
Posts: 317
Thanks: 24
Thanked 3 Times in 3 Posts
macleodjb is on a distinguished road
Try removing the quotes from $new_amount

Quote:
Originally Posted by eberdome View Post
PHP Code:
$update_balance mysql_query("UPDATE `members` SET `balance` = $new_amount WHERE `username` = '".$username."'"); 
macleodjb is offline   Reply With Quote
Old 01-30-2011, 12:35 AM   PM User | #3
eberdome
Regular Coder

 
Join Date: Dec 2010
Location: California
Posts: 193
Thanks: 28
Thanked 8 Times in 8 Posts
eberdome is an unknown quantity at this point
sorry, that did nothing
eberdome is offline   Reply With Quote
Old 01-30-2011, 12:49 AM   PM User | #4
macleodjb
Regular Coder

 
Join Date: Apr 2007
Posts: 317
Thanks: 24
Thanked 3 Times in 3 Posts
macleodjb is on a distinguished road
to me it sounds like you have a syntax issue with your mysql query.

Try printing out the values of deduct amount and the original amount and see if they are populated.

Remove the slashes from your query as shown. I always get more issues adding them then without.
I added the die() statement to the end of your query so you can see what is happening.
Quote:
Originally Posted by eberdome View Post
PHP Code:
$update_balance mysql_query("UPDATE members SET balance = $new_amount WHERE username = '".$username."'") or die(mysql_error()); 
macleodjb is offline   Reply With Quote
Old 01-30-2011, 01:10 AM   PM User | #5
eberdome
Regular Coder

 
Join Date: Dec 2010
Location: California
Posts: 193
Thanks: 28
Thanked 8 Times in 8 Posts
eberdome is an unknown quantity at this point
that didn't work, i think it has something to do with

PHP Code:
$myPaypal->ipnData['payment_gross']; 
I dont think its recognizing this, but this info can be entered into paypal.txt and that seems to work
eberdome is offline   Reply With Quote
Old 01-30-2011, 01:51 AM   PM User | #6
macleodjb
Regular Coder

 
Join Date: Apr 2007
Posts: 317
Thanks: 24
Thanked 3 Times in 3 Posts
macleodjb is on a distinguished road
You have to try and trace down what is not working. If you think that is the problem try touble shooting that variable by printing it or checking its type. Print everything out and see what is missing.
macleodjb is offline   Reply With Quote
Reply

Bookmarks

Tags
database, paypal, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:59 AM.


Advertisement
Log in to turn off these ads.