# Sending checkbox entries to a custom table in wordpress not working

**URL:** <https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601>\
**Category:** Get Help\
**Tags:** wpdb, log-everything, logging, gform\_after\_submission\
**Created:** [August 30, 2019, 3:54pm UTC](https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601 "2019-08-30T15:54:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chest\_Heart\_Stroke\_S](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@Chest\_Heart\_Stroke\_S](https://community.gravityforms.com/u/Chest_Heart_Stroke_S)\
**Post date:** [August 30, 2019, 3:54pm UTC](https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601/1 "2019-08-30T15:54:19Z")

</div>

Hi,  
Apologies for the question if it is a duplicate, but I have not been able to find a solution.

In wordpress, I am capturing the input from a form and grabbing it and sending it to a custom table like so:

```
add_action('gform_after_submission_1', 'add_entry_to_db', 10, 2);

function add_entry_to_db($entry, $form) {
  $first_name = $entry[1]; //a normal text input & varchar field
  $topic = $entry[2]; // a checkbox input with 3 options & varchar field

global $wpdb;

// add form data to custom database table
	$wpdb->insert(
	    'zzz_customtable',
	    array(

    'first_name' => $first_name,
    topic' => $topic
	    )
	);
}

```

I can’t get any input to appear in the database from the $topic variable.  
Any ideas where I am going wrong?  
I can get inputs from all other field types.

Thanks!  
Jason

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [August 30, 2019, 9:45pm UTC](https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601/2 "2019-08-30T21:45:16Z")

</div>

I don’t have any idea where you are going wrong. But when doing something custom like this, you should log everything. Be sure that [logging is active](https://docs.gravityforms.com/logging-and-debugging/) on the site already for Gravity Forms Core (to log all messages.) Then add some logging statements to your code. Follow the examples here:

> **[Custom Logging Statements - Gravity Forms Documentation](https://docs.gravityforms.com/custom-logging-statements/#writing-to-the-core-log)**
>
> While Gravity Forms and its add-ons include numerous logging statements sometimes you may need to add more. This article explains how to add custom logging.

I recommend logging every variable or object after you think you have set the value, to be sure it contains what you expect it to. Log the entry right after you enter the function. Log the results from `$wpbd->insert`. Do something like this:

```auto
$result = $wpdb->insert(
	'zzz_customtable',
	array(
		'first_name' => $first_name,
		'topic' => $topic
	)
);

GFCommon::log_debug( __METHOD__. "(): WPDB Insert result is {$result}." );

```

You might also consider using `$wpdb->prepare` rather than insert directly.  
[https://codex.wordpress.org/Function\_Reference/wpdb\_Class#Protect\_Queries\_Against\_SQL\_Injection\_Attacks](https://codex.wordpress.org/Function_Reference/wpdb_Class#Protect_Queries_Against_SQL_Injection_Attacks)

---

<div class="post-metadata">

**Author:** ![Chest\_Heart\_Stroke\_S](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@Chest\_Heart\_Stroke\_S](https://community.gravityforms.com/u/Chest_Heart_Stroke_S)\
**Post date:** [December 4, 2019, 9:34am UTC](https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601/3 "2019-12-04T09:34:17Z")

</div>

Hi,  
So I figured this out eventually; sorry for not posting sooner.

The issue is accessing the way GF does arrays from checkbox inputs.  
I discovered in the documentation that it is done like so:  
$topic[‘2.3’] // This accesses the third variable in the check box array.

It is important to note that this does not follow the arrays starting at 0 convention; so instead of the third variable being $topic[‘2.2’], it is in fact $topic[‘2.3’].

Hope this helps someone else!  
Kind regards  
Jason

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [December 4, 2019, 12:22pm UTC](https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601/4 "2019-12-04T12:22:09Z")

</div>

Thank you for posting that update!

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [January 4, 2022, 5:14pm UTC](https://community.gravityforms.com/t/sending-checkbox-entries-to-a-custom-table-in-wordpress-not-working/2601/5 "2022-01-04T17:14:09Z")

</div>

Closed on January 4, 2022, 5:14pm UTC


