这是我第一次使用构建数据库并使用$ _POST函数。我正在使用paypal IPN集成构建一个简单的表单。表单基本上只是一个paypal按钮和一些动态填充的隐藏输入,它看起来像这样:
deposit.php
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin'; //
$paypal_id='malik@thedistractionsband.co.uk'; // Business email ID
$booking_form_id = $the_query->post->ID;
$total_amount = get_post_meta( $the_query->post->ID, 'wedding_price', true );
$deposit_amount = $total_amount*0.2;
?>
<h3>Pay Deposit</h3>
<p>Your deposit aount of £<?php echo $deposit_amount; ?> ...</p>
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<input type="hidden" name="payment_type" value="deposit">
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo get_post_meta( $the_query->post->ID, 'wedding_name', true ); ?> - 20% Deposit">
<input type="hidden" name="wedding_name" value="<?php echo get_post_meta( $the_query->post->ID, 'wedding_name', true ); ?>">
<input type="hidden" name="the_user" value="<?php echo $current_user->ID; ?>">
<input type="hidden" name="item_number" value="<?php echo $booking_form_id; ?>">
<input type="hidden" name="credits" value="510">
<input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>">
<input type="hidden" name="amount" value="<?php echo $deposit_amount; ?>">
<input type="hidden" name="cpp_header_image" value="http://www.thedistractionsband.co.uk/files/2015/08/LOGO-1.1-1024x304.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="handling" value="0">
<input type="hidden" name="cancel_return" value="<?php echo get_site_url()."/payment-cancel/"; ?>">
<input type="hidden" name="return" value="<?php echo get_site_url()."/my-bookings/"; ?>">
<input name="notify_url" value="<?php echo DISTRACTIONS_LOGIN_PLUGIN_URL ?>includes/payments/paypal-ipn.php" type="hidden">
<input type="submit" border="0" name="submit" class="paypal_btn" value="PAY NOW WITH PAYPAL" alt="PayPal - The safer, easier way to pay online!">
</form>
您将看到通知URL使用文件paypal-ipn.php与paypal进行通信。如果pament成功,我也会使用此文件将数据发送到我的数据库中的自定义表格 - 这个文件我遇到了问题:
贝宝ipn.php
<?php
// Make wordpress functions available - so we can write to the db etc
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' );
global $wpdb;
$item_name = $_POST['item_name']; // wedding name
$booking_id = $_POST['item_number']; // booking id
$user_id = $_POST['user_id']; // user id
$user_name = $_POST['wedding_name']; // user id
$the_user = $_POST['the_user']; // user id
$payment_status = $_POST['payment_status']; // payment status
$payment_amount = $_POST['mc_gross']; // amount?
$payment_currency = $_POST['mc_currency']; // currency
$txn_id = $_POST['txn_id']; // transaction id
$receiver_email = $_POST['receiver_email']; // reciever email i.e. your email
$payer_email = $_POST['payer_email']; // payer email i.e. client email
$payment_type = $_POST['payment_type']; // payer email i.e. client email
// Mark deposit as paid
if (strcmp ($payment_status, "Pending") == 0 || strcmp ($payment_status, "Completed") == 0) {
update_post_meta($booking_id, 'deposit_paid', 1);
// Send email here
}
// Insert results into deposits table
$wpdb->insert(
'wp_distr_deposit_payments',
array(
'payment_user_id' => $the_user,
'booking_id' => $booking_id,
'user_name' => $user_name,
'item_name' => $item_name,
'payment_status' => $payment_status,
'payment_amount' => $payment_amount,
'payment_currency' => $payment_currency,
'transaction_id' => $txn_id,
'receiver_email' => $receiver_email,
'user_email' => $payer_email
),
array(
'%d',
'%d',
'%s',
'%s',
'%s',
'%d',
'%s',
'%d',
'%s',
'%s',
)
);
?>
我的问题是其中两个字段没有发送到数据库。它们是user_name和payment_user_id
我一遍又一遍地检查,并确定它不是语法错误。在我的error_log文件中,我收到以下错误:
[01-Dec-2015 19:56:02 UTC] PHP Notice: Undefined index: wedding_name in /home/samskirrow/public_html/distractions-login/wp-content/plugins/distractions-login/includes/payments/paypal-ipn.php on line 11
[01-Dec-2015 19:56:02 UTC] PHP Notice: Undefined index: the_user in /home/samskirrow/public_html/distractions-login/wp-content/plugins/distractions-login/includes/payments/paypal-ipn.php on line 12
这让我相信deposit.php中的隐藏字段(the_user和user_name - 不是由$ _POST方法发送/拾取)
任何人都可以帮我找到解决方案,让它正常工作。