I got the undefined variable : user_id when i use get_user_meta
This is because $user_id
is empty and undefined, you need to give it a value, and that value needs to be the ID of a user.
when i try put the above code below this line
no error occur but my value $phone and $icno become empty
Yes, you gave $user_id
a value so it worked. The reason phone and icno are empty is because there is no user meta for phone and icno. The order you do things in matters. Code is executed from the top of the file to the bottom.
You can't retrieve values before they are added, and you can't use variables before they are set.
2 final notes:
- indenting your code is important, especially if you share it with other people, and it eliminates an entire class of bugs
global $wpdb, $user_ID;
should be removed. The code never uses$wpdb
and there is no$user_ID
global variable unlesssetup_userdata
is called.