4 Replies Latest reply on Jun 5, 2008 10:07 PM by Jovin49

    Regarding Accessing HTTP

    arav5566 Level 1
      I copied the below program from help content of adobe (For accessing http service-flex builder).The program will call a http service and receive the data and display it in a datagrid. The problem is the output data is not getting displayed in the datagrid. Not sure why is it so. This is a program in help part of adobe. I created the table, inserted the data as mentioned in the help. I tested the php weblink( http://localhost:8080/testuser.php) in the IE separately and it is working.

      Pasted the programs below
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      xmlns="*" creationComplete="send_data()">
      <mx:Script>
      <![CDATA[
      private function send_data():void {
      userRequest.send();
      }
      ]]>
      </mx:Script>
      <mx:Form x="22" y="10" width="493">
      <mx:HBox>
      <mx:Label text="Username"/>
      <mx:TextInput id="username"/>
      </mx:HBox>
      <mx:HBox>
      <mx:Label text="Email Address"/>
      <mx:TextInput id="emailaddress"/>
      </mx:HBox>
      <mx:Button label="Submit" click="send_data()"/>
      </mx:Form>
      <mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.users.user}">
      <mx:columns>
      <mx:DataGridColumn headerText="User ID" dataField="userid"/>
      <mx:DataGridColumn headerText="User Name" dataField="username"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:List>

      <mx:TextInput x="22" y="292" id="selectedemailaddress"
      text="{dgUserRequest.selectedItem.emailaddress}"/>
      <mx:HTTPService id="userRequest" url=" http://localhost:8080/testuser.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <username>{username.text}</username>
      <emailaddress>{emailaddress.text}</emailaddress>
      </mx:request>
      </mx:HTTPService>
      </mx:Application>


      PHP Program
      -------------------

      <html>
      <head>
      <title>PHP Test</title>
      </head>
      <body>
      <?php
      define( "DATABASE_SERVER", "localhost" );
      define( "DATABASE_USERNAME", "root" );
      define( "DATABASE_PASSWORD", "admin123" );
      define( "DATABASE_NAME", "rssDB" );

      //connect to the database.
      $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);

      mysql_select_db( DATABASE_NAME );

      // Quote variable to make safe
      function quote_smart($value)
      {
      // Stripslashes
      if (get_magic_quotes_gpc()) {
      $value = stripslashes($value);
      }
      // Quote if not integer
      if (!is_numeric($value)) {
      $value = "'" . mysql_real_escape_string($value) . "'";
      }
      return $value;
      }
      /*
      if( $_POST["emailaddress"] AND $_POST["username"])
      {
      //add the user
      $Query = sprintf("INSERT INTO users VALUES ('', %s, %s)", quote_smart($_POST['username']), quote_smart($_POST['emailaddress']));

      $Result = mysql_query( $Query );
      }
      */
      //return a list of all the users
      $Query = "SELECT * from users";
      $Result = mysql_query( $Query );

      $Return = "<users>";

      while ( $User = mysql_fetch_object( $Result ) )
      {
      $Return .= "<user><userid>".$User->userid."</userid><username>".$User->username."</username><emailad dress>".$User->emailaddress."</emailaddress></user>";
      }
      $Return .= "</users>";
      mysql_free_result( $Result );
      print ($Return)
      ?>
      </body>
      </html>