Flex input and output in PHP

I want to print input value to flex in PHP.

My Flex Code ...

<mx:HTTPService id="sendReq" result="google(event)" showBusyCursor="true" method="POST" url="http://localhost/search/index.php" useProxy="false">
        <mx:request xmlns="">
            <keyword>
                {keyword.text}
            </keyword>
        </mx:request>
    </mx:HTTPService>

    <mx:TextInput text="" id="keyword" left="130.5" top="89" right="228.5" height="40" fontSize="20" fontWeight="bold" borderStyle="outset" focusThickness="0"/>

    <mx:Button click="sendReq.send();" id="search" label="search"  right="133.5" top="91" height="40" width="75" alpha="1.0" fillAlphas="[1.0, 1.0]"/>

      

My PHP code,

$keyword = $_POST['keyword'];
echo $keyword;

      

But I cannot get the keyword from Flex. Can anyone find an error here that I cannot get.

0


a source to share


5 answers


I don't have time to solve this problem, but here are some tips for debugging it:

First, I would trace everything in the opening tag for your HTTPRequest.

<mx:HTTPService id             = "sendReq" 
                result         = "trace( event )" 
                fault          = "trace( event )" 
                showBusyCursor = "true" 
                method         = "POST" 
                url            = "http://localhost/search/index.php"
                useProxy       = "false">

      

If something is wrong with your request, you have absolutely no way of knowing that your request does not have an error handler!

On the PHP side, the best way to debug an application like this is with some kind of logging system.



Here's a pretty general logging function:

define( 'PATH_TO_LOG_FOLDER', "../Logs" );

public function log( $message ){
    $logFileName = "log";
    if(!$fp = @fopen(PATH_TO_LOG_FOLDER. DIRECTORY_SEPARATOR . 
             $logFileName .date('Y-m-d').".log", 'a+')){
        return FALSE;
    }

    flock(  $fp, LOCK_EX  );    
    fwrite( $fp, $message );
    flock(  $fp, LOCK_UN  );
    fclose( $fp );
}

      

On http: //localhost/search/index.php call

$message = "";
for( $_REQUEST as $key => $val )
{
    $message .= "$key = $val\n";
}
log( $message );

      

+1


a source


Have you tried using FireBug? it is a firefox extension that can show you exactly what is going on and connecting between flex client and server.



+1


a source


Check if your request reaches your php script (i.e. writes a line to the beginning of the script). To see what's coming into the script:

print_r(getallheaders());
print_r($HTTP_RAW_POST_DATA);
print_r($_POST); 

      

Sorry, can't help with flex :(.

0


a source


I would start by writing a php script that takes input and emails or logs to a file to make sure you have half the transaction sent; then, once you are sure you are working, move on to verifying that the expected result is returned.

0


a source


In the past, when I used httpservice, I didn't set the method parameter (default is "get")

So, I used something like

<mx:HTTPService id="myCall" 
    url="{'somephp.php'}"
    result="resultHandler(event)" 
    fault="faultHandler(event)"
    showBusyCursor="false" 
    resultFormat="e4x"> 
    <mx:request>
        <somethingToSend>post data inside here</somethingToSend>
        <time>{new Date().getTime()}</time>
    </mx:request>
</mx:HTTPService>

      

Then inside php I will have

$ someVarThatsjustComeThrough = $ _REQUEST ["somethingToSend"];

If all you responded using php, please repeat it in XML format. This will make your work easier on the flexible side.

Always insert the time, it stops IE from potentially caching the php call.

0


a source







All Articles