How to split data and insert in different columns using WP DataTables [closed]


I’ve just asked this question in StackOverflow ( but I think it might be more suitable here.

Im building a wordpress website that uses a form (using GravityForm plug in) and inserts into a table (WP DataTables plugin). The form takes information to place an order for groceries.

The way I currently insert the values of the field is by doing the following in my php file.

 $wpdb->insert( $table, array(
        'datecreated'           => date( 'Y-m-d' ),
        'name'                  => $entry[34],
        'productselected        =>$entry[36],

Where the entry number is the field ID number in the form.

This works fine.

I have the “product selected” as a radio button, and I want it to have a value also for the price, so the name and it’s value are inserted into the database in separate columns. For example, “eggs” will have a value of 3 and “milk” to have a value of 5. Then my data table will have “eggs” in the “product selected” column and “3” in the “productvalue” column. Image to show radio button with name and value

At the minute, it only passes in the value, and wrongly in the “productselected” column. I need the name to in the “productselected” column and “productvalue” to have the value of the whatever the selection was, in this case 3.

I believe I need to use regex to split this out and insert, something like this

 $wpdb->insert( $table, array(
        'datecreated'               => date( 'Y-m-d' ),
        'name'                      => $entry[34],
        'productselected'           =>$entry[36].name,
        'productvalue'              =>$entry[36].value

But not sure what the correct syntax would be

Any help appreciated as Ive searched the internet and spent days on this.

Thanks in advance

, Chillin' 4 years 2020-03-27T12:51:23-05:00 0 Answers 88 views 0

Leave an answer