• Resolved ENHAdmin

    (@enhadmin)


    I’ve looked and looked and can’t quite find the answer to what I’m looking to do.

    I’ve looked at the Codex and found the PHP code to collect the current user id. However there’s a warning, so I wanted to ask the community if it’s possible and direction on how to complete this.

    So here’s the situation: I have an application written in PHP and MySQL that’s separate of WP. What I’m wanting to do is collect the logged in users ID, post it to the database for this app. And then join those two later when the user calls their postings.

    Here’s how the process looks: User logs in, navigates to form, when form is submitted; form collects and posts the current users ID into a userid field in the database.

    Later I will add: join of database, select from tbl where userid=’userid’.

    The user must be logged in in order to view the form. My file structure is in the sites root directory.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ENHAdmin

    (@enhadmin)

    I think what I’ll have to do is: use the same code that requires login, on the action page, define $current_user_id as get_current_user_id(), then with the mysqli_query, insert into tbl (userid) values($current_user_id). Wish me luck everyone!

    I would like this to stay open until it’s been solved, for anyone else looking for the same thing.

    Thread Starter ENHAdmin

    (@enhadmin)

    Here is the resolution as of now:

    on the action page you must call the get_current_user_id function in PHP. I got it prior to making the connection with the Database. I then inserted it into the tbl with a value of: $current_user_id (This will depend on the variable you define).

    Make sure that the action file is in your root directory so it will properly require the wp-load and wp-blog-header.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get current user ID then post into separate database’ is closed to new replies.