使用值从重力表单提交创建mysql表

时间:2017-06-23 01:10:16

标签: php mysql wordpress forms gravity

我已将此代码添加到重力形式插件功能(www.allurice.com/dashboard)

 ///**add database table
register_activation_hook( __FILE__, 'endo_create_custom_table' );

function endo_create_custom_table() {

global $wpdb;

$table_name = $wpdb->prefix . "form5_table";

$sql = "CREATE TABLE $table_name(
    id mediumint(9) NOT NULL AUTO_INCREMENT, 
    PlatForm varchar(2),
    Gamesform date,
    Hometeam decimal(4,2) NULL,
    DomeS decimal(4,2) NULL,
    WeaTHers decimal(4,2) NULL,
    Windy decimal(4,2) NULL,
    Injured decimal(4,2) NULL,
    BackupPotential decimal(4,2) NULL,
    VegasODD decimal(4,2) NULL,
    ProjectedPPG1 decimal(4,2) NULL,
    CompletinsAllowed decimal(4,2) NULL,
    OPassDR decimal(4,2) NULL,
    ORushDR decimal(4,2) NULL,
    3LastWeeks decimal(4,2) NULL,
    UNIQUE KEY id(id)
    ) COLLATE utf8_general_ci;";

require_once(ABSPATH . '/wp-admin/includes/upgrade.php');

dbDelta($sql);

}

此代码用于添加数据库表,但是当我将此代码添加到我的主题的functions.php时,它不会将条目添加到表中,我无法弄清楚为什么?

///**Add form to database table
add_action( 'gform_after_submission_5', 'endo_add_entry_to_db', 10, 2);
function endo_add_entry_to_db($entry, $form) {

 echo '<pre>';
  var_dump($entry);
  echo '</pre>';

$source = $entry['source_url'];
  $Username1 = $entry['user'];
  $Platform1 =  $entry[16];
  $Games1 =     $entry[17];
  $Home1 =  $entry[4];
  $Dome1 =  $entry[5];
  $Weather1 =   $entry[7];
  $Wind1 =  $entry[14];
  $Injury1 =    $entry[8];
  $backup1 =    $entry[6];
  $Vegas1 =     $entry[9];
  $projected1 =     $entry[13];
  $OCA1 =   $entry[10];
  $OPDR1 =  $entry[11];
  $ORDR1 =  $entry[12];
  $Last3 =  $entry[15];





global $wpdb;

// add form data to custom database table
$wpdb->insert(
    'wpx9_form5_table',
    array(
      'id' => $Username1,
      'PlatForm' => $Platform1,
      'Gamesform' => $Games1,
      'Hometeam' => $Home1,
      'DomeS' => $Dome1,
      'WeaTHers' => $Weather1,
      'Windy' => $Wind1,
      'Injured' => $Injury1,
      'BackupPotential' => $backup1,
      'VegasODD' => $Vegas1,
      'ProjectedPPG1' => $projected1,
      'CompletinsAllowed' => $OCA1,
      'OPassDR' => $OPDR1,
      'ORushDR' => $ORDR1,
      '3LastWeeks' => $Last3,
    )
);

}

0 个答案:

没有答案