doulin9679 2015-12-08 08:15
浏览 27

Paypal付款成功后无法更新MySQL行

I have successfully set up the Paypal button and can receive email from my IPN code. However, I am not sure how to know which user actually made the payment. My doubt is that The email address used by user may not be the same as the one used to signup from my service. I tried to grab username from $_SESSION but it returns empty string. Here is my code:

if (strcmp ($res, "VERIFIED") == 0) {
$txn_id = $_POST['txn_id'];
$payment_amount = $_POST['mc_gross'];
$payment_status = $_POST['payment_status'];
$payment_time = date("Y-m-d H:i:s");
$username = $_SESSION['user'];
$body = $txn_id.' '.$payment_amount.' '.$payment_status.' '.$payment_time.' '.$username;
mail("Email Address", 'Subject', $body, ''); 
$connection = new mysqli('localhost', 'user', 'password', 'db');
$query       = $connection->query("UPDATE members SET TRANSID = '$txn_id', PAYAMOUNT = '$payment_amount', PAYSTATUS = '$payment_status', PAYTIME =     '$payment_time' WHERE USERNAME ='$username'");
mysqli_close($connection);

I have also added session_start(); at the beginning of ipn.php. What should I do to update data for correct user.

UPDATE

I am using Paypal IPN system. A user can pay with Paypal on the upgrade page. Then Paypal sends me transaction details on ipn.php. Now, I am writing code in ipn.php to update the MySQL table.

UPDATE TWO

After suggestion from steammike this is what I have.

Now my code looks like this:

$txn_id = $_POST['txn_id'];
$payment_amount = $_POST['mc_gross'];
$payment_status = $_POST['payment_status'];
$payment_time = date("Y-m-d H:i:s");
$username = $_POST['fuser'];

and my button like this:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ATXN4EP7FQXR8">
<input type="hidden" name="fuser" value="<?php echo $_SESSION['user'];?>">
<input type="submit" name="submit" value="Pay With Paypal" class="btn btn-primary">
</form>

The $username variable is still blank though.

UPDATE 3

I am still unable to update the Table after changing fuser to custom in button like this:

<input type="hidden" name="custom" value="<?php echo $_SESSION['user'];?>">

and form like this:

$username = $_POST["custom"];

The only thing that gets updated is 'PAYTIME'. Although in the email I receive all the data. This is the structure of table:

TRANSID     varchar(20)
PAYAMOUNT   decimal(7,2)
PAYSTATUS   varchar(25)
PAYTIME     datetime
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分