• Resolved supernova42

    (@supernova42)


    If a record for a user does not exist in the Participants DB, then how can I create a dummy record which the user can later amend. I’ve included the code that I’m using to get the username from WordPress which in turn is used to find the associated record in PDB.

    $current_user = wp_get_current_user();
    $wp_username = $current_user->user_login;
    $user_id = Participants_Db::get_record_id_by_term(‘username’, $wp_username);

    if(empty($user_id)) {
    echo ‘$user_id is empty – Create a dummy record here’;
    }
    else { /* Record exists – display record */
    $record = Participants_Db::get_participant($user_id);
    echo do_shortcode(‘[pdb_record tabs=true fields=”username,name,address,city,country” record_id=’.$user_id.’]’);
    }

    Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter supernova42

    (@supernova42)

    I’ve got the following statement that creates a record with a record_id, but all the fields are empty. What am I doing wrong?

    if(empty($user_id)) {
    $data=array(‘user_name’ => $wp_username);
    Participants_Db::write_participant($data);
    }

    The other problem is that it actually creates 3 blank records instead of 1 every time I run the routine.

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    You’re doing it right in general, but check your data array to make sure it has the expected data in it.

    I don’t know why you’re getting 3 records, I would assume that your code is getting called multiple times.

    Thread Starter supernova42

    (@supernova42)

    Sorted

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a PDB dummy record in php’ is closed to new replies.