0 Replies Latest reply on Aug 17, 2007 9:17 AM by Shark_Attack

    HttpService problems

    Shark_Attack Level 1
      Hello everyone! I want to insert some data into a mysql database table so i have a httpservice called postBlog which does this.

      I pass 4 parameters to the php script through this i.e. title,body,username,keywords. A button called submit is used to call postBlog.send(). I have a result event which simply alerts the user that the blog has been entered successfully. When i click the button after a few seconds the alert message appears. However no data is entered into the database.

      The mxml code for this app is:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute">
      <mx:HTTPService id="postBlog" url=" http://localhost/postblog.php" result="postBlogSuccess(event)" useProxy="false" method="POST">
      <mx:request xmlns="">
      <title>{txtBlogTitle.text}</title><body>{txtBlogEntry.text}</body><keywords>{txtBlogKeywo rds.text}</keywords><username>{lblShowUserName.text}</username>
      </mx:request>
      </mx:HTTPService>
      <mx:Script>
      <![CDATA[
      import flash.events.*;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.http.HTTPService;

      private function postBlogSuccess(evt:ResultEvent):void {
      mx.controls.Alert.show("Entry posted successfully");
      }

      ]]>
      </mx:Script>
      <mx:TextInput x="236" y="94" id="txtBlogTitle" text="test"/>
      <mx:TextInput x="236" y="164" id="txtBlogEntry" text="work"/>
      <mx:TextInput x="236" y="231" id="txtBlogKeywords" text="please"/>
      <mx:Label x="236" y="47" text="Mike" width="145" id="lblShowUserName"/>
      <mx:Button x="496" y="318" label="Button" click="postBlog.send()"/>

      </mx:Application>

      The corresponding php script is:

      <?php
      define( "DATABASE_SERVER", "localhost" );
      define( "DATABASE_USERNAME", "root" );
      define( "DATABASE_PASSWORD", "" );
      define( "DATABASE_NAME", "blog" );

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

      mysql_select_db( DATABASE_NAME );

      //data passed from flex

      $title = mysql_real_escape_string($_POST["title"]);

      $body = mysql_real_escape_string ($_POST["body"]);

      $keywords = mysql_real_escape_string ($_POST["keywords"]);

      $username = mysql_real_escape_string ($_POST["username"]);

      //add the user to user table
      $Query ="INSERT INTO dbblog (title, body, keywords, username) VALUES ('$title', '$body', '$keywords', '$username')";

      $Result = mysql_query( $Query );

      mysql_close($mysql);

      ?>

      I have no idea why this is not working. I think the php script is correct so the problem must lie with my flex code. Im really at a dead end and was wonderin if anyone has got any ideas where the problems lies? I using flex builder 2 and Xampp is where my php and msql are locatated if thats makes any difference.