从获取$_POST值向定制表中插入数据

时间:2015-06-05 作者:user3463054

我使用print_r()

  Array ( [0] => test [1] => [email protected] [2] => 1.00 [3] =>    21:16:36 Jun 04, 2015 PDT [4] => 9DS7592P74GMN ) 
现在我想在自定义表中添加此数据,但我不能。

这是我的密码

  if(!empty($_POST))
  {
    $player_name = $_POST[\'first_name\'];
    $payer_email = $_POST[\'payer_email\'];
    $payment_gross = $_POST[\'payment_gross\'];
    $payment_date = $_POST[\'payment_date\'];
    $payer_id = $_POST[\'payer_id\'];

    $paypal_str = array($player_name, $payer_email, $payment_gross, $payment_date, $payer_id);
 print_r($paypal_str);

global $wpdb;
$wpdb->insert(
    \'paypal\',
     array(
        \'name\' =>  $paypal_str[0],
        \'email\' => $paypal_str[1],
        \'amount\' => $paypal_str[2],
        \'player_id\' => $paypal_str[3],
        \'date\' => $paypal_str[4],
    )
);
}

2 个回复
SO网友:sarath

if(!empty($_POST))
  {
    $player_name = $_POST[\'first_name\'];
    $payer_email = $_POST[\'payer_email\'];
    $payment_gross = $_POST[\'payment_gross\'];
    $payment_date = $_POST[\'payment_date\'];
    $payer_id = $_POST[\'payer_id\'];

    $paypal_str = array($player_name, $payer_email, $payment_gross, $payment_date, $payer_id);
 print_r($paypal_str);

global $wpdb;
$wpdb->insert(
    \'paypal\',
     array(
        \'name\' =>  $paypal_str[0],
        \'email\' => $paypal_str[1],
        \'amount\' => $paypal_str[2],
        \'player_id\' => $paypal_str[3],
        \'date\' => $paypal_str[4]
    )
);
}
从数组中删除不需要的逗号。

SO网友:user3463054

嘿,伙计们,它工作正常。

 if(!empty($_POST)){

 global $wpdb;
 $player_name = $_POST[\'first_name\'];
 $payer_email = $_POST[\'payer_email\'];
 $payment_gross = $_POST[\'payment_gross\'];
 $payment_date = $_POST[\'payment_date\'];
 $payer_id = $_POST[\'payer_id\'];

 $wpdb->insert( 
\'wp_paypal\', 
array( 
    \'name\' => $player_name, 
    \'player_id\' =>$payer_id,
    \'email\' =>  $payer_email,
    \'amount\' => $payment_gross,
    \'payment_date\' => $payment_date
), 
array( 
    \'%s\', 
    \'%s\',
    \'%s\',
    \'%s\',
) 
);

 }

结束

相关推荐

meaning of (array)function()

我看到了这段代码,其中包含了我以前从未见过的部分代码。在此场景中,(数组)的行为是什么?到目前为止,我知道用php创建数组的方法,但从未见过这种情况。// $this->settings = array_merge( $this->settings_defaults(), (array) get_option( $this->settings_slug, $this->settings_defaults() ) ); // &#x