views:

52

answers:

2

I am trying to figure out why I can't include a function into this. I am trying to make it so $client will make it's way into the request string. http://test.com/next.xml?file=$client&test=againtest

$client IS DEFINED as text from my database.

function update($pro){
    $request = 'http://test.com/next.xml?file='.$client'&'.'test='.urlencode($pro);;
    $postargs = 'status='.urlencode($pro);
    return $this->process($request,$postargs); 
}

Is there a certain way to do this? This doesn't give me any PHP errors, but it's not working right. If I remove '.$client.' and replace it with just plain text such as text it works, but when I include it as a function, it won't work.

+4  A: 

It looks like $client isn't defined.

If that variable is defined out of the function's scope, it will not be available unless you define it as a global variable

global $client

This is discouraged though, a better way of doing this is to pass $client as a parameter to the function

Have a look here for more on variable scopes http://php.net/manual/en/language.variables.scope.php

Andrei Serdeliuc
+2  A: 

You should change your code like this, you forget about string concatenation:

$request = 'http://test.com/next.xml?file=' . $client . '&test=' . urlencode($pro);

Use whitespaces between dots and strings - just make a rule for this. And you will see all you typos!

Sergey Kuznetsov