Title: WP $current.user
Last modified: August 31, 2016

---

# WP $current.user

 *  [hellman.c](https://wordpress.org/support/users/hellmanc/)
 * (@hellmanc)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp-currentuser/)
 * i am trying to grabb some data and only show data that have the same value as
   the current user
 * iam using the plugin php insert
 * the code i am using
 *     ```
       $sql = "SELECT * FROM Medlemar Where Medl_nr= . $current_user->Medl_nr% .";
       ```
   
 * Medl_nr is a custom field in wp.users table i created
 * and with $current_user->Medl_nr is giving me the value if i run the code seperat.
 * but running the query then i am only getting 0 result.
    soo it seem like the 
   query can´t get the current_user data (that should be a number and in this case
   it is number 25)
 * soo am i doing something wrong or am i missing something
 * all the code i am using
 *     ```
       [insert_php]
   
       $servername = "db host";
       $username = "user";
       $password = "pass";
       $dbname = "db_1";
   
       // Create connection
       $conn = mysqli_connect($servername, $username, $password, $dbname);
       // Check connection
       if (!$conn) {
           die("Connection failed: " . mysqli_connect_error());
       }
       $sql = "SELECT * FROM Medlemar Where Medl_nr= . $current_user->Medl_nr% .";
       $result = $conn->query($sql);
   
       if ($result->num_rows > 0) {
           // output data of each row
           while($row = $result->fetch_assoc()) {
         echo "Medl_nr: " . $row['Medl_nr']. " - Namn: " . $row["namn"]. " " . $row["efternamn"]. "<br>";;
           }
       } else {
           echo "0 results";
       }
       $conn->close();
   
       [/insert_php]
       ```
   
 * the wp db and the db1 i am trying to get data from is on diffrent servers.

The topic ‘WP $current.user’ is closed to new replies.

## Tags

 * [current_user](https://wordpress.org/support/topic-tag/current_user/)
 * [external server](https://wordpress.org/support/topic-tag/external-server/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [Remote MySQL](https://wordpress.org/support/topic-tag/remote-mysql/)
 * [remote server](https://wordpress.org/support/topic-tag/remote-server/)

 * 0 replies
 * 1 participant
 * Last reply from: [hellman.c](https://wordpress.org/support/users/hellmanc/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/wp-currentuser/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
