doutao1171 2016-07-06 16:02
浏览 201
已采纳

如何将联系表单7数据插入wordpress中的mysql数据库

Please go through the below code, i am trying to insert my contact form 7 data into my mysql table(i.e. wp_tps_forms). In this case i copy paste below code in my functions.php file of theme, but it's didn't work.

add_action('wpcf7_before_send_mail', 'save_form');
function save_form($wpcf7)
{
    global $wpdb;
    $title = $wpcf7->title();

    $company_name=$wpcf7->posted_data["company-name"];
    $email=$wpcf7->posted_data["your-email"];
    $start_year=$wpcf7->posted_data["start-year"];
    $team=$wpcf7->posted_data["team"];
    $business_model=$wpcf7->posted_data["business-model"];
    $sub_category_business=$wpcf7->posted_data["sub-category-business"];
    $competition=$wpcf7->posted_data["competition"];
    $phase_of_business=$wpcf7->posted_data["phase-of-business"];
    $stage_of_product=$wpcf7->posted_data["stage-of-product"];
    $customer_traction=$wpcf7->posted_data["customer-traction"];
    $estimate_funding=$wpcf7->posted_data["estimate-funding"];
    $website_url=$wpcf7->posted_data["website-url"];
    $contact_number=$wpcf7->posted_data["contact-number"];
    $what_does_your_company_do=$wpcf7->posted_data["what-does-your-company-do"];
    $core_team=$wpcf7->posted_data["core-team"];
    $what_is_unique_selling_point=$wpcf7->posted_data["what-is-unique-selling-point"];
    $go_to_market=$wpcf7->posted_data["go-to-market"];
    $any_other_information=$wpcf7->posted_data["any-other-information"];
    $link_to_url=$wpcf7->posted_data["link-to-url"];
    $file=$wpcf7->posted_data["file-01"];

    $wpdb->insert( $wpdb->prefix . 'tps_forms', 
            array('id' => '','form'  => $submited['title'],'company-name'=> '$company_name','your-email' => '$email','start-year' => '$start_year','team' => '$team','business-model' => '$business_model','sub-category-business' => '$sub_category_business','competition' => '$competition','phase-of-business' => '$phase_of_business','stage-of-product' => '$stage_of_product','customer-traction' => '$customer_traction','estimate-funding' => '$estimate_funding','website-url' => '$website_url','contact-number' => '$contact_number','what-does-your-company-do' => '$what_does_your_company_do','core-team' => '$core_team','what-is-unique-selling-point' => '$what_is_unique_selling_point','go-to-market' => '$go_to_market','any-other-information' => '$any_other_information','link-to-url' => '$link_to_url','file-01' => '$file','date' => date('Y-m-d H:i:s')));
}

Please suggest me the proper way to do this.

  • 写回答

1条回答 默认 最新

  • douxunwei7083 2016-07-10 11:32
    关注

    @Fencer04's suggestion to use Contact Form 7 To Database Extension is probably a great lead and timesaver. Plugin unavailable.

    However, if you do want to resolve your insert issue, I suggest you try updating your insert function as follows (read more on $wpdb):

    $wpdb->insert( 
    'wp_table',                              // the table prefix and name
        array(
            'company-name'=> $company_name,  // single quote the key, do not quote variables
            'start-year' => $start_year   // single quote the key, do not quote variables
            )
        ),
        array(                               // optional, but wise, include array telling wordpress the datatype
            '%s',                            // corresponds to company-name, string
            '%d'                             // corresponds to start year, digit
        )
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败