If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

2 arrays with simplexml load string failing

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 except for opening and closing tags and I'm getting a syntax error, unexpected T_VARIABLE on line 42:
//$query_vals = array();

The reason for that syntax error is you're missing a semi-colon on the line above $query_vals = array(); . After you fix that, there are 3 other errors. First, your foreach loops aren't doing anything as you're immediately ending them with a ; and have no { } around them. I'm guessing you're trying to write nested foreach loops, which should be:

PHP Code:

foreach($query_vals as $key => $value) {// since $key and $value are used in the outer loop // you need to use different variable names for the inner loop // otherwise you'll over-write $key and $value each time!foreach($current_user_info as $key2 => $value2) {

}}

Second, you have a randomly-placed { on the line $result = array_merge($query_vals, $current_user_info); . Third, you have the closing randomly-placed } just after $postdata .= $key.'='.urlencode($value).'&';

$postdata = '';
$current_user_info = wp_get_current_user();
foreach($query_vals as $key => $value) {
// since $key and $value are used in the outer loop
// you need to use different variable names for the inner loop
// otherwise you'll over-write $key and $value each time!
foreach($current_user_info as $key2 => $value2) {

$postdata = '';$current_user_info = wp_get_current_user();foreach($query_vals as $key => $value) {// since $key and $value are used in the outer loop // you need to use different variable names for the inner loop // otherwise you'll over-write $key and $value each time!foreach($current_user_info as $key2 => $value2) {

this function has infinite recursion (i.e. $current_user = wp_get_current_user();). also the variable scope is not established ($current_user_info is only available within wp_get_current_user()) nor is there a return value.

this function has infinite recursion (i.e. $current_user = wp_get_current_user();). also the variable scope is not established ($current_user_info is only available within wp_get_current_user()) nor is there a return value.

The code you saw there is a recent change from 4 hours ago that was suggested by another developer who said my (other code) I had was wrong. It seems I keep making code changes based on suggestions, and nothing seems to work and then others say the last code change was wrong.

Php is one of the most difficult things to master I've ever attempted. I'm no closer now that I was a week ago because no code suggestions I've received from about seven developers has worked. I don't know what to think, or how this is going to get resolved.

yea the initial hurdles of learning php may seem overwhelming. the "strictness" of php is actually beneficial for debugging.
let's break down your function and try to get it to function right.$value and $type from where are we getting these variables from?
what's going on here?

PHP Code:

$current_user-> $value;$n="user_variable_{$type}_name"; ${$n} = true;

in php (as well as most languages) "-" is an operator. you'll need to either verify that this is in fact the key/property naming convention used in the returned value from wp_get_current_user_info()

Is crap. I read a post today from 2011 that says since WordPress 3.3 (current version now is 3.9), that the way custom user fields are called is different. The post > http://goo.gl/x5deHi says the way to call custom WP fields like 5 of mine are, is like this:

i suggest when naming global variables, functions, and/or classes that extend or are in tandem with scripts that are not your own to not use the naming conventions they use. this could cause naming conflicts down the road.

Thanks ShrineDesigns, I see your logic after reading the post I read earlier today. I noticed how you started the array with the standard WP user fields and then called the custom fields. But what is the post string is expecting the fields in their original order? Do you feel they would be accepted in that order? That's my concern.