PHP variable in WordPress database query

The WPDB prepare method is what you’re after, as this will prep your data for passing to a query and also ensure data matches the type its intended to be whilst also handling quoting where necessary at the same time.

Fixing your code could be a matter of..

$voucher="MK0186";
$is_in_database = $wpdb->get_results( "SELECT * FROM my_codes_table WHERE code="$voucher"" );

.. but you’d be better advised to write it this way ..

$voucher="MK0186";

$is_in_database = $wpdb->get_results( 
    $wpdb->prepare( "
        SELECT * FROM my_codes_table 
        WHERE code = %s", 
        $voucher 
    ) 
);

Example query with 2 numeric values and a string value.

$num1 = 5;
$num2 = 10;
$string = 'Some String!!';
$query = $wpdb->get_results( 
    $wpdb->prepare( "
        SELECT * FROM sometable 
        WHERE column1 = %d 
        AND column2 = %d
        AND column3 = %s
        ", 
        $num1, $num2, $string
    ) 
);

In short… your string value isn’t quoted, that’s the issue. Use the $wpdb->prepare method and it’ll take care of that for you.