Problem creating a user on a different WordPress using $wpdb (6 posts)

  1. victorwu89
    Posted 4 years ago #

    I am trying to create a user on a different wordpress site through the submission of a form using POST.

    The way it functions is that the user clicks a button that has a hidden form supplying information through method POST to a CRM that will than also send a method POST to a php file on the site of the wordpress that the user should be created. The code is as follows:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    For some reason it creates the user on the original wordpress site of where they clicked the button rather than the other wordpress site. I am extremely confused and I think it has to do wit the $wpdb being called to the wrong database.

  2. Are these separate dbs? I mean, not Multisite but two separate sites?

  3. victorwu89
    Posted 4 years ago #

    Yes, these are two separate dbs or sites.

  4. Moving this to WP advanced.

    Can you post the code you're using on Pastebin.com?

  5. victorwu89
    Posted 4 years ago #

    Here's the code.


  6. TCBarrett
    Posted 4 years ago #

    There is nothing in the pastebin code that indicates you are making a new database connection, just that you are using the standard global $wpdb variable. Assuming this is correct, your code needs to be in the WordPress install where the user is to be created, not the site you are submitting from. (but that raises other issues).

    If you are wanting to have two databases open at the same time, you should explicitly open a new connection. You can use the wpdb() class for this:

    $otherdb = new wpdb('username','password','database','localhost');

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.