3 Replies Latest reply on Apr 7, 2010 2:55 AM by David_F57

    Simple mysql table row update


      Hi all,


      I am new to flex. Literally days into this. I have followed an example from the flex 3 bible and created a Flex applciation calling an AMFPHP service. I got the hello world to appear and was pretty chuffed with that. (code used is below)

      I have been asked to use some php code that I used to successfully add a row to my database. Apparently this is easy but I'm not getting it.

      All I want to do in this instance is add one row of data to my table. I guess I would just insert my php code in as a statement somewhere right?


      The table is on a server


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          <mx:RemoteObject id="phpService"
          source="MyClass. HelloWorld"/>
          <mx:Button label="Say Hello" click="phpService.sayHello()"/>
          <mx:Label text="{phpService.sayHello.lastResult}"/>


      Below: Is this the right bit of code that would update?


      var sql:String =
          "INSERT INTO mytable (Row1, Row2, Row3 , Row4, Row5, Row6, Row7, Row8, Row9 , Row10) " +
          "VALUES ('Data1', 'Data2',  'Data3', 'Data4', 'Data5', 'Data6', 'Data7', 'Data8', 'Data9', 'Data10')";
      insertStmt.text  = sql;


      I really am confused by all this.


      Thanks in advance for any help

        • 1. Re: Simple mysql table row update
          Matt Le Fevre Level 4

          your PHP query string looks sound, doesn't look like there would be any problems there.


          my experience with AMFPHP is non-existant, but i'd guess PHP knowledge that your query simply isn't being sent to the database somehow.




          Cut your code down so it's just trying to insert one item, get that working and go from there. Maybe look around on google for a working 'amfphp insert example' and compare what you have to that.


          I have a working flex/php example here:




          so you can compare your PHP syntax against that to make sure it's correct

          • 2. Re: Simple mysql table row update
            daslicht Level 2


            your query String will INSERT not UPDATE existing data.


            You want something like this:


            UPDATE "table_name"
            SET "column_1" = [new value]
            WHERE {condition}





            To check out if your statement is the right one, you can try it using phpmyadmin at the SQL Statement section.


            In case you have Flash Builder 4 you could try the DataWizard which will create working code from a existing Database for you.


            Cheers Marc

            • 3. Re: Simple mysql table row update
              David_F57 Level 5



              here is a bit of code that may help you, when using amfphp you would have the php class that updates the record, to call that class from flex you would declare it as a remote object. You then send that object with the data to the server where the sql updates the table. The code below is for inserting a record updating a record requires a slightly different sql statement but the principle is pretty much the same.


              If you are using flashbuilder you can use zendamf and the data wizard will create your actionscriptcode and your php services code.





                   Actionscript code to update a record through amfphp

              <mx:RemoteObject id="catalog" fault="onFault(event)" showBusyCursor="true" source="qiksales" destination="amfphp">

                      <mx:method name="newCategory" result="isEntered(event)" />



                   private function AddCategory(e:MouseEvent): void





                   Php function

              function newCategory($group, $category) {

                   $mysql = mysql_connect(localhost,"root","");

                   mysql_select_db( "catalog" );

                   $Query = "INSERT INTO categorys (groupID, name) VALUES ('$group', '$category')";

                   $Result = mysql_query( $Query );