0

I am having an issue with using global variables to get values inserted into my custom database table:

// example that does not work 
$user = wp_get_current_user();
$mega = $user->user_login;   // this values will return blank when
                             // inserted into database especially 
                             // when used with an if statement. 

The values work fine within the code in making a database query, but once inserted into the database it returns a blank empty value.

    // here is my full code
    global $wp;
    $user = wp_get_current_user();
    $mega = $user->user_login;
    $age = 19;

    // if records were not found in the database 
    // then insert new row with the details
    if ( $age == 19) {
        $fillup = $wpdb->insert("markrecord_table", array(
            "username" => $mega,
            "post_id" => 340,
            "counted" => 1,
        )); 
    }
2
0

Please try with the updated code

// here is my full code
global $wpdb;
$user = wp_get_current_user();
$mega = $user->user_login;
$age = 19;

// if records were not found in the database 
// then insert new row with the details
if ( $age == 19) {
    $fillup = $wpdb->insert("markrecord_table", array(
        "username" => $mega,
        "post_id" => 340,
        "counted" => 1,
    )); 
}
0

Thanks everyone, @Pat J you pointed out the real issue, i shoud have used if ($age == 19) that comparison operator == fixed the issue and have updated my code above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.