简体   繁体   English

WordPress将重力表单数据插入新表

[英]WordPress insert Gravity Form data into new table

I have a WordPress site that I am using a gravity form. 我有一个使用重力形式的WordPress网站。 I would like to take one of the gravity forms I am using and insert the data into another table. 我想采用我正在使用的一种重力形式,并将数据插入到另一个表中。 (Besides the gravity form table). (在重力表格旁边)。 I am using the Gravity Form after submission hook to grab the values of my specific form (3) and run a SQL statement. 我在提交钩子之后使用Gravity Form来获取我特定表单(3)的值并运行SQL语句。 Here is a link explaining about the hook: http://www.gravityhelp.com/documentation/page/Gform_after_submission 这是解释有关该钩子的链接: http : //www.gravityhelp.com/documentation/page/Gform_after_submission

However, nothing gets inserted into the new table (users). 但是,没有任何内容插入到新表(用户)中。 I can't even tell if the script is running. 我什至不知道脚本是否正在运行。 Both the "default" gravity form table and my new users table are in the same database. “默认”重力形式表和我的新用户表都在同一数据库中。 Here's what my PHP looks like: 这是我的PHP的样子:

add_action("gform_after_submission_3", "input_fields", 10, 2);
function input_fields($entry, $form){


                    $entry["1"] = '$name';
                    $entry["2"] = '$email';
                    $entry["3"] = '$purchase_date';
                    $entry["4"] = '$order_number';

   $SQL = "INSERT INTO users ( userID, email, name, purchase_date, order_number) VALUES ( '', '$email' , '$name', '$purchase_date', '$order_number')";
   }

I'm grabbing the values using the Gravity Form entry object. 我正在使用“重力窗体”输入对象来获取值。 More info about that here: http://www.gravityhelp.com/documentation/page/Entry_Object 有关此的更多信息,请访问: http : //www.gravityhelp.com/documentation/page/Entry_Object

The form writes to the default table alright but not to my new "users" table. 该表格会写入默认表,但不会写入我的新“用户”表。 Any suggestions? 有什么建议么? Let me know if I need to give more info. 让我知道是否需要提供更多信息。 Thanks for any help! 谢谢你的帮助!

Try this following code... 试试下面的代码...

add_action('gform_after_submission_3', 'input_fields', 10, 2);
function input_fields($entry, $form){
global $wpdb;
               $name = $entry['1'];
               $email = $entry['2'];
               $purchase_date =  $entry['3'];
               $order_number = $entry['4'];

  $SQL = "INSERT INTO users ( userID, email, name, purchase_date, order_number) VALUES ( '', '$email' , '$name', '$purchase_date', '$order_number')";
  $wpdb->query($SQL);
 }

Thank you.... 谢谢....

You have created the query but you are not executing it. 您已创建查询,但未执行查询。

add_action("gform_after_submission_3", "input_fields", 10, 2);
function input_fields($entry, $form){
    global $wpdb;


                    $entry["1"] = '$name';
                    $entry["2"] = '$email';
                    $entry["3"] = '$purchase_date';
                    $entry["4"] = '$order_number';

   $SQL = "INSERT INTO users ( userID, email, name, purchase_date, order_number) VALUES ( '', '$email' , '$name', '$purchase_date', '$order_number')";
   $wpdb->query($SQL);
   }

Also I assume that you have already created the users table. 我还假设您已经创建了users表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM