feed wp-Gravity form input to custom sql table

Backgound: I have a wordpress installation with a basic myslq database structure managed by cpanel. I have implemented Gravity Forms plugin to generate a type of contact us form. If a customer has a question/complaint about a product, they fill the form out and submit. This will then go into a custom table (wp-contacts) I have created within the wp database. I use an ODBC connector to connect the data in the table with Filemaker. Our Customer Service team then can see the data in the custom filemaker application we developed and they can respond to the question.

Problem: I am having issues with my PHP script that is supposed to send the gravity from data input from the customer to the custom sql table I created. When I test the from and enter in sample data and click submit, I get a this page cannot be displayed error. Furthermore, there is no data present in the custom table I created. There is also the question of the captcha. I have implemented a captcha in the gravity forms, so I would assume I need some sort of field to set to 1 or 0 if the captcha was checked? What would be the best way to implement this? Here is my Script:

add_action("gform_after_submission_1", "input_fields", 10, 2);
function input_fields($entry, $form)
{
	global $rhodesba_rhodes;

		$entry["12"] = '$fname';
		$entry["14"] = '$lname';
		$entry["4"] = '$email';
		$entry["5"] = '$address1';
		$entry["15"] = '$address2';
		$entry["16"] = '$city';
		$entry["18"] = '$state';
		$entry["17"] = '$zip';
		$entry["7"] = '$bbd';
		$entry["6"] = '$upc';
		$entry["10"] = '$subject';
		$entry["2"] = '$question';

	$SQL = "INSERT INTO wp_contacts (id, name, last_name, state, city, address, address_2, bbd, subscribe, upc, email, subject, comments, phone, user_ip, answer, answered_by, zipcode, category_id, active, contact_captcha, answered_date, dept, computer_name, created) VALUES ('', '$fname', '$lname', '$state', '$city', '$address1', '$address2', '$bbd', '', '$upc', '$email', '$subject', '$question', '', '', '', '', '$zip', '', '', '', '', '', '', '')";
	$rhodesba_rhodes->query($SQL);
}

There are fields in my table that do not populate via the gravity forms contact us form. Rather, those fields are manipulated by our Customer Server team when answering a question in their filemaker app (i.e- answer, answered_by, etc.) and are used by filemaker for other purposes. For these fields, I used a place holder ''. My ID field is set to auto-increment for each record added.
image of database structure

Answers

So, after some research I figured this out. I am posting the solution in case anyone else has this same question. Here is my updated code:

add_action("gform_after_submission_1", "input_fields", 10, 2);
function input_fields($entry, $form)
    {
        $password = "password";
		$username = "username";
		$servername = "localhost";
		$dbname = "db";
		$fname = $entry["12.3"];
		$lname = $entry["14.6"];
		$email = $entry["4"];
		$address1 = $entry["5.1"];
		$address2 = $entry["15.2"];
		$city = $entry["16.3"];
		$state = $entry["18.4"];
		$zip = $entry["17.5"];
		$bbd = $entry["7"];
		$upc = $entry["6"];
		$subject = $entry["10"];
		$question = $entry["2"];

$con=mysqli_connect($servername, $username, $password, $dbname);
mysqli_query($con,"INSERT INTO wp_contacts (id, name, last_name, state, city, address, address_2, bbd, subscribe, upc, email, subject, comments, phone, user_ip, answer, answered_by, zipcode, category_id, active, contact_captcha, answered_date, dept, computer_name, created) VALUES ('', '$fname', '$lname', '$state', '$city', '$address1', '$address2', '$bbd', '', '$upc', '$email', '$subject', '$question', '', '', '', '', '$zip', '', '', '', '', '', '', '')");
    }



My first issue was I had the variable declarations assigned in the opposite way.

$entry["12"] = $fname //WRONG
$fname = $entry["12"] //RIGHT

Once I took care of this, I started getting data to populate in the mysql table, however, only certain fields were populating. After further investigation, I noticed that my id's being used to access the $entry were incorrect. In order to get the correct id's, I right clicked on each field in the browser and inspected the element. This showed me a name attribute like this: name="input_1.3". The numbers after the "input_" prefix are the id to use for the $entry. I changed the id's I had wrong, and now the data is posting perfectly.

I also used this to connect to the database:

mysqli_connect

Hope this helps if anyone has a similar question.

Posted on by Sharrison