在数据库中存储Paypal详细信息

时间:2013-12-10 10:01:07

标签: php paypal

我正在建立一个网上购物的样本网站,但我被困在这里。当我将所有细节插入数据库时​​,未成功插入itemname和order_id,其余字段工作正常。

这是表格的代码:

<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="add" value="1">
                <input type="hidden" name="business" value="example@gmail.com">
                <input type="hidden" name="item_name" value="<?php echo  $_SESSION['itemname'];?>">
                <input type="hidden" name="item_number" value="<?php echo $_SESSION['itemnum'];?>">
                <input type="hidden" name="amount" value="1">
                <input type="hidden" name="shipping" value="0">
                <input type="hidden" name="shipping2" value="0">
                <input type="hidden" name="handling" value="0">
                <input type="hidden" name="currency_code" value="USD">
                <input type="hidden" name="return" value="example.com">
                <input type="hidden" name="notify_url" value="example.com" />
                <input type="hidden" name="quantity" value="1">
                <input type="submit" style="margin-top:10px; background:url(images/btn_bg1.png); color:#FFFFFF;"  border="0" name="addtocart" value="Download@ 1$" width="87" height="23" alt="Make payments with PayPal - it's fast, free and secure!">
                </form>

以下代码用于将详细信息存储在数据库中。

$item_name = $_POST['item_name'];
        $business = $_POST['business'];
        $item_number = $_POST['item_number'];
        $payment_status = $_POST['payment_status'];
        $mc_gross = $_POST['mc_gross'];
        $payment_currency = $_POST['mc_currency'];
        $txn_id = $_POST['txn_id'];
        $receiver_email = $_POST['receiver_email'];
        $receiver_id = $_POST['receiver_id'];
        $quantity = $_POST['quantity'];
        $num_cart_items = $_POST['num_cart_items'];
        $payment_date = $_POST['payment_date'];
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $payment_type = $_POST['payment_type'];
        $payment_status = $_POST['payment_status'];
        $payment_gross = $_POST['payment_gross'];
        $payment_fee = $_POST['payment_fee'];
        $settle_amount = $_POST['settle_amount'];
        $memo = $_POST['memo'];
        $payer_email = $_POST['payer_email'];
        $txn_type = $_POST['txn_type'];
        $payer_status = $_POST['payer_status'];
        $address_street = $_POST['address_street'];
        $address_city = $_POST['address_city'];
        $address_state = $_POST['address_state'];
        $address_zip = $_POST['address_zip'];
        $address_country = $_POST['address_country'];
        $address_status = $_POST['address_status'];
        $tax = $_POST['tax'];
        $option_name1 = $_POST['option_name1'];
        $option_selection1 = $_POST['option_selection1'];
        $option_name2 = $_POST['option_name2'];
        $option_selection2 = $_POST['option_selection2'];
        $for_auction = $_POST['for_auction'];
        $invoice = $_POST['invoice'];
        $custom = $_POST['custom'];
        $notify_version = $_POST['notify_version'];
        $verify_sign = $_POST['verify_sign'];
        $payer_business_name = $_POST['payer_business_name'];
        $payer_id =$_POST['payer_id'];
        $mc_currency = $_POST['mc_currency'];
        $mc_fee = $_POST['mc_fee'];
        $exchange_rate = $_POST['exchange_rate'];
        $settle_currency = $_POST['settle_currency'];
        $parent_txn_id = $_POST['txn_id'];
        $pending_reason = $_POST['pending_reason'];
        $reason_code = $_POST['reason_code'];
        if (($_POST['payment_status']=='Completed') && ($_POST['receiver_email'] == 'vishalmiddha103@gmail.com')){
            $fecha = date("m")."/".date("d")."/".date("Y");
            $fecha = date("Y").date("m").date("d");

           //check if transaction ID has been processed before
            $checkquery = "SELECT id from paypal_payment_info where id='".$parent_txn_id."'";
            $sihay = mysql_query($checkquery);
            $nm = mysql_num_rows($sihay);
                if ($nm == 0){
                    if ($txn_type == "web_accept"){
                      $strQuery = "INSERT into paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,order_id,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
                            values ('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$custom."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."',
                            '".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";

                            $result = mysql_query($strQuery) or die("Cart - paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());




                    }
                    else{

                        $strQuery = "insert into paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,m c_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendi ngreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$item_number."','".$item_name."','".$option_name1."','".$option_selection1."','".$option_name2."','".$option_selection2."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
                        $result = mysql_query("insert into paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendi ngreason,reasoncode,tax,datecreation) values ('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$item_number."','".$item_name."','".$option_name1."','".$option_selection1."','".$option_name2."','".$option_selection2."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')") or die("Default - paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());

                    }

                }
                else{
                  echo 'Sorry,Transaction id already exists';

                }

        }
        else{
           echo "<div class=\"errortext\">We cannot verify your purchase. Please contact ".ADMINMAIL."</div>";

        }

2 个答案:

答案 0 :(得分:2)

php数据库中的

custom未在您的表单中声明添加此行<input type="hidden" name="custom" value="yourvalue">。确保您的$_SESSION['itemname'];有效。

答案 1 :(得分:0)

请尝试调试代码。 在数据库中插入数据之前,您可以尝试打印print_r($ _ POST)和print_r($ _ SESSION)。