Foreach loop not working as expected – custom tables and references while submitting a form

So the first part of your question is just how to get the contents of wp_redskaber into radio buttons. As you’ve attempted, use $wpdb->get_results(); to query the table. By default each row will be an Object, so you’d output it like this:

global $wpdb;

$results = $wpdb->get_results( "SELECT * FROM wp_redskaber" );

foreach ( $results as $redskaber ) {
    echo sprintf( 
        '<label><input type="radio" name="redskabs_id" value="%s"> %s</label>', 
        esc_attr( $redskaber->redskabs_id ), 
        $redskaber->redskabs_navn
    );
}

Because get_results() returns an array of objects, you get the id and name of each column with object notation: $redskaber->redskabs_id, and $redskaber->redskabs_nav.

So I’ve looped over each result and created a radio button input for each. Radio buttons should all have the same name, but different values. In this case I’ve given them the name redskabs_id. Note that I’ve used sprintf() to put the column values into the HTML. I find this neater than opening and closing strings or PHP tags, but you can do it whatever way you like.

So when the form is submitted you access the selected ID with $_POST['redskabs_id'].

So in your second block of code, you set $redskabsID to:

$redskabsID = $_POST['redskabs_id'];

$wpdb->insert() will properly escape it for SQL for you, so you’re safe there, but for some extra validation you might want to confirm that it’s a number with absint():

$redskabsID = absint( $_POST['redskabs_id'] );

That will get the ID inserted into the reg_redskabs_id column. You don’t need to do anything special to link them. As long as the ID in that column matches an ID in the wp_redskaber table you can match them.

If you’re doing some validation and want to be absolutely certain that $redskabsID is a valid ID in the wp_redskaber table, you can get an array of valid IDs using $wpdb->get_col(), and then compare that to the submitted value:

global $wpdb;

$valid_redskabs_ids = $wpdb->get_col("SELECT redskabs_id FROM wp_redskaber");

if ( ! in_array( $_POST['redskabs_id'], $valid_redskabs_ids ) ) {
    // Invalid redskabs_id submitted. Handle error here.
}