• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Sending php variables to Flash Builder

New Here ,
May 18, 2010 May 18, 2010

Copy link to clipboard

Copied

Hi guys,

I have made a form which when sent to a Mysql server adds a table to a database.

Here is the code that I use in Flash Builder:

...

<mx:HTTPService id="srv" url="http://mysite.com/addTeam.php" method="POST">

<mx:request>

<teamName>{teamName.text}</teamName>

<city>{city.text}</city>

</mx:request>

</mx:HTTPService>

...

<mx:Form x="25" y="10">

<mx:FormHeading label="Add a team"/>

<mx:FormItem label="Team name">

<s:TextInput id="teamName"/>

</mx:FormItem>

<mx:FormItem label="City">

<s:TextInput id="city"/>

</mx:FormItem>

<mx:FormItem>

<s:Button label="Add" click="srv.send()"/>

</mx:FormItem>

And here is my addTeam.php file:

<?php

  $teamName = $_POST['teamName'];
  $city = $_POST['city'];
  $addteam = $teamName ." ". $city;
  $connection = mysqli_connect("host", "username", "password", "db") or die(mysqli_connect_error());
  mysqli_query($connection, "SET CHARACTER SET utf8");  //the added table will be in bulgarian language
  $sql = "CREATE TABLE `$addteam`
  (
  FirstName varchar(20),
  SurName varchar(20),
  LastName varchar(20),
  position varchar(20),
  price int
  )
  ";
  mysqli_query($connection, $sql) or die ("Query failed: " . mysqli_error($connection));
 

?>

My question is: How can I return some text to Flash Builder if the query was successful or failed (like "echo") so that the user (admin in this case) knows what is going on and not just clicking the add button and having to go to phpmyadmin to see if the table has been created or not?

Views

882

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , May 18, 2010 May 18, 2010

You have this declared

<mx:HTTPService

id="srv" url="http://mysite.com/addTeam.php" method="POST">

just add

result="yourResultHandler()"/>

then create the function that would handle the result.

<mx:HTTPService

id="srv" url="http://mysite.com/addTeam.php" method="POST" result="yourResultHandler(event)">

Votes

Translate

Translate
Engaged ,
May 18, 2010 May 18, 2010

Copy link to clipboard

Copied

After you do a mysql_query(

Mysql returns a rows affected, so just do PHP logic on that rows affected.

so if you're rows affected is 1, then it's success

return "Success"

If your rows affected is 0 then it didnt' get added to MySQL

return "Fail"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2010 May 18, 2010

Copy link to clipboard

Copied

Well , the point is that I don't know how to use the return statement... Or at least how to include it in the mxml code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 18, 2010 May 18, 2010

Copy link to clipboard

Copied

Sorry I don't use MXML.  Here's how you would do it in actionscript, there's probably a similar option in mxml.

private function submitResultHandler(event:ResultEvent):void

{

     if(event.result == "Success")

     {

     }

     else

     {

     }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2010 May 18, 2010

Copy link to clipboard

Copied

Could you give me a full example. As I told you - I'm quite new, especially to ActionScript...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 18, 2010 May 18, 2010

Copy link to clipboard

Copied

You have this declared

<mx:HTTPService

id="srv" url="http://mysite.com/addTeam.php" method="POST">

just add

result="yourResultHandler()"/>

then create the function that would handle the result.

<mx:HTTPService

id="srv" url="http://mysite.com/addTeam.php" method="POST" result="yourResultHandler(event)">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2010 May 19, 2010

Copy link to clipboard

Copied

LATEST

I don't know why but this doesn't work... Can you copy the whole code that I should put both in my php and mxml files because I got rather confused. I'm trying to make an alert pop up but no mather if the table exists or not it shows 1 and the same result...

EDIT:

Actually I managed to fix it...

I replaced the return statement with echo and just made the text of the alert to be event.result and it showed as it should. Thanks for your help!

Appreciate it...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines