Syntax
The issue with your WordPress approach is the get_var
calls used to get the subscriber id and interest name. get_var
is intended to get just a variable from the database like the number of rows in the table or sum of a numeric column in the table, see the WordPress Codex
What your looking to do is select a row, using get_row
public function update_subscriber_interest($subscriber_id, $interest_name) {
global $wpdb;
$select_subscriber_id = $subscriber_id;
$select_interest_name = $interest_name;
$get_subscriber_id = $wpdb->get_row(
"SELECT * FROM {$wpdb->prefix}subscriber WHERE id = ".$select_subscriber_id.""
);
$get_interest_name = $wpdb->get_row(
"SELECT * FROM {$wpdb->prefix}interest WHERE name="".$select_interest_name."""
);
$sql = $wpdb->insert(
"{$wpdb->prefix}subscriber_interest",
array(
"id" => $get_subscriber_id->id,
"name" => $get_interest_name->name
),
array(
'%d',
'%s'
)
);
return $sql;
}
Table Structure
The table structure you describe is going to give you an subscriber_interest table that links to the interest table using a non-unique column the name, so if there are two seperate interest rows that are both named RSVP things are going haywire.
I’d recommend using the id column to link the interest table to the subscriber interest.