admin管理员组

文章数量:1316516

I am trying to insert a value into a column after a user registers.

Sadly after my test I get the error "Write Error" what could be wrong with the hook?

function org_teammember( $user_id ) {
    $teammember = 'yes';

    $sql = "INSERT INTO wp_usermeta (ocp_team_member)".
    "VALUES('$user_id','$teammember')";

    $result = mysqli_query($wpdb, $sql) or die('Write Error!');

 }```

I am trying to insert a value into a column after a user registers.

Sadly after my test I get the error "Write Error" what could be wrong with the hook?

function org_teammember( $user_id ) {
    $teammember = 'yes';

    $sql = "INSERT INTO wp_usermeta (ocp_team_member)".
    "VALUES('$user_id','$teammember')";

    $result = mysqli_query($wpdb, $sql) or die('Write Error!');

 }```
Share Improve this question edited Oct 15, 2020 at 10:01 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Oct 14, 2020 at 14:36 Sebastian BulearcaSebastian Bulearca 112 bronze badges 2
  • 1 Why don't you just use a function WordPress already has update_user_meta()? developer.wordpress/reference/functions/update_user_meta There is no need to write a custom SQL queries – geouser Commented Oct 14, 2020 at 14:51
  • Thank you very much @geouser – Sebastian Bulearca Commented Oct 14, 2020 at 15:04
Add a comment  | 

1 Answer 1

Reset to default 0

Used the method of @geouser

Why don't you just use a function WordPress already has update_user_meta()? developer.wordpress/reference/functions/update_user_meta There is no need to write a custom SQL queries

本文标签: Add value in user table when user is created