• 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.