Jump to content

2 arrays with simplexml load string failing


Recommended Posts

Hey guys,

Sorry, php noob here, but can grasp new concepts rather quickly. I've been in IT a long time and this is my first time trying to rewrite this much php code. I've been working on this php script for 7 days now and think I'm getting close. I've seen most every syntax error, have learned a lot and morphed the code into what it is now.

The script I'm hacking was written back in 09 with 16 (static) user data fields in an array to test register a user at a third-party website via SSL with curl and a simple xml load string. If you get a success response, all went well with the other server. If not, all you get is a fail response.

The first 6 data fields will still remain static, but the last 10 will always vary because I'm querying a WP user DB to get user data. The script just queries the WP user DB creates an array and posts to the other server and registers the user, so the user that registered with the first site doesn't have to go through the whole registration process over again. This is totally G-rated. It's for a consumer discounts site.

Here's what I'm trying to get the code to do. Create an array, query the DB and then pass the first static array data and the user array data to the post string and get a success response from the other server.

This is the whole script that's failing and I'm only able to see, Status: fail. Nice error code huh?

Here's my code:


    // Set the Query POST parameters
    $query_vals = array(
        'api_username' => 'api-name-here',
        'api_password' => 'api-password',
        'api_key' => 'key-goes-here',
       'perkalert' => 0,
       'offer_radius' => 20,
       'send_welcome_email' => 1


    // Call WordPress function wp_get_current_user_info()
    //Create array
    function wp_get_current_user_info() {
        $current_user = wp_get_current_user();
       $current_user-> $value;
       ${$n} = true;
        $current_user_info = array(
                'firstname' . $current_user->user_firstname =>'n',
                'lastname' .  $current_user->user_lastname =>'n',
                'address' . $current_user->mepr-address-one =>'n',
                'city' . $current_user->mepr-address-city =>'n',
                'state' . $current_user->mepr-address-state =>'n',
           'zip' . $current_user->mepr-address-zip =>'n',
           'country' . $current_user->mepr-address-country =>'n',
           'email' . $current_user->user_email =>'n',
           'username' . $current_user->user_login =>'n',
           'password' . $current_user->user_pass =>'n'

        return $current_user_info;

    $postdata = '';
    $key = '=';
    $value = '&'
    $query_vals = array();
    $current_user_info = array();
    $result = array_merge($query_vals, $current_user_info); {
    foreach($query_vals as $key => $value);
    foreach($current_user_info as $key => $value);
    $postdata .= $key.'='.urlencode($value).'&';


    // Chop of the trailing ampersand
    $postdata = rtrim($postdata, '&');

    // create a new cURL resource
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://secureserver/client/register_member.xml');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

    // Save response to a string
    $response = curl_exec($ch);

    $xml = simplexml_load_string($response);

    echo "Status: ".$xml->status;

Any help is really appreciated. Thanks.

Link to comment
Share on other sites

Line 6 assigns a populated array to $query_vals. Line 42 assigns an empty array to $query_vals.


Line 18 starts a function but you are not calling it.


Line 44 is a complete statement, but is followed by a brace that usually groups statements to be executed via a program flow construct.


Line 45,46 are program flow constructs with nothing to do.


Line 49 is the closing brace to line 44, but line 44 is not a program flow construct.

Link to comment
Share on other sites

A lot of what you mentioned makes sense. So if I lose line 42 the first array should be fine correct? I should do something to call my function on line 18. (thanks developer on wordpress.stackexchange.com) who suggested the code... Now the rest starts to get confusing and seems like more reading on php.net... Thanks.

Link to comment
Share on other sites

Feel free to ask specific questions. "It don't work" is not specific.


"If I lose line 42, the first array should be fine."


Yes. And also for line 43. Odds are good this array will get populated somewhere earlier in the script. You don't want to empty it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.