4 Replies Latest reply on May 28, 2007 5:15 PM by XMLmaster

    Get value from PHP

    XMLmaster
      Hi, I am learning FLEX and I was having trouble getting a value from a PHP file upon request. What am I doing wrong?

      PHP
      <?
      $item = "Hello World!";
      $return .= "<test>".$item."</test>";
      $return .= $_POST['return'];
      print($return)
      ?>

      MXML

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" >
      <mx:HTTPService id="userRequest" url=" http://localhost/test.php" result="lbl1.text">
      <mx:request xmlns="">
      <test>{lbl1.text}</test>
      </mx:request>
      </mx:HTTPService>
      <mx:Button x="327" y="92" label="Get Info" click="userRequest.send()"/>
      <mx:Label x="159" y="66" width="160" id="lbl1"/>
      </mx:Application>
        • 1. Re: Get value from PHP
          mouse jockey
          Is you webserver/PHP configuration setup to recognize PHP short tags? If not, use <?php instead of just <?
          • 2. Re: Get value from PHP
            XMLmaster Level 1
            Hi,

            It is. My PHP is returning <test>Hello World!</test> but FLEX 2 is not picking it up.
            Its very fustrating
            • 3. Re: Get value from PHP
              BLXWebMaster Level 1
              I am not quite sure what you are trying to accomplish. Appears you are trying to do a post and you will be returning different data. Here is a working example of the component and php that returns the lbl1.text via alert.

              Also, don't know much about your PHP code, but your snippet has sytax issues, at least with PHP5. Not sure about the dots. I have included a working simple version.


              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application
              xmlns:mx=" http://www.adobe.com/2006/mxml"
              xmlns="*"
              layout="absolute" >
              <mx:Script>
              <![CDATA[
              import mx.rpc.events.*;
              import mx.events.*;
              import mx.controls.*;

              private function userRequestRPCResult(event:ResultEvent):void {
              Alert.show(event.result.toString());
              }

              // Fault handler - displays the error
              private function userRequestRPCFaultHandler(event:FaultEvent):void
              {
              Alert.show(event.fault.message, "Could not load 1.php");
              }
              ]]>
              </mx:Script>

              <mx:HTTPService
              id="userRequest"
              url=" http://localhost/test.php"
              method="POST"
              result="userRequestRPCResult(event);"
              fault="userRequestRPCFaultHandler(event);">
              <mx:request xmlns="">
              <test>{lbl1.text}</test>
              </mx:request>
              </mx:HTTPService>

              <mx:Button x="327" y="92" label="Get Info" click="userRequest.send()"/>
              <mx:Label x="159" y="66" width="160" id="lbl1" text="TEST DATA"/>
              </mx:Application>

              <?php
              echo $_POST["test"];
              ?>

              • 4. Re: Get value from PHP
                XMLmaster Level 1
                Thanks! That was it.