2 Replies Latest reply on Jul 2, 2010 11:14 AM by =VA=FyreHeart

    Datagrid and Update php script not working

    djh88ukwb Level 1

      I have a datagrid pulling data from an array,  my code is this.

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler()">
        
          <fx:Declarations>
              <mx:RemoteObject id="db_services" fault="db_services_faultHandler(event)" showBusyCursor="true">      
                  <mx:method name="testfunction" result="qrytestfunction(event)"/>  
              </mx:RemoteObject>
            
              <mx:HTTPService id="swapservice" url="swap.php" method="POST" result="swapResult(event)">
              </mx:HTTPService>
          </fx:Declarations>
        
          <fx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                  import mx.events.FlexEvent;
                  import mx.events.ListEvent;
                  import mx.managers.PopUpManager;
                  import mx.rpc.events.FaultEvent;
                  import mx.rpc.events.ResultEvent;          
                  import spark.events.IndexChangeEvent;
                  import spark.events.TextOperationEvent;  
                
                  [Bindable] private var resultArr:ArrayCollection = new ArrayCollection();
                
                  [Bindable] public var selectedID:String;
                
                  protected function db_services_faultHandler(event:FaultEvent):void          
                  {          
                      // Alert.Show("something went wrong")              
                  }
                
                  private function qrytestfunction(res:ResultEvent):void          
                  {          
                      resultArr = res.result as ArrayCollection;          
                  }
                
                  protected function application1_creationCompleteHandler():void          
                  {              
                      db_services.endpoint = "http://localhost/amfphp/gateway.php";              
                      db_services.source = "jobs";          
                      db_services.destination = "amfphp";          
                      db_services.getOperation("testfunction").send();
                  }
                
                  protected function clicky(event:ListEvent):void          
                  {          
                  selectedID = event.itemRenderer.data.id;
                  swapservice.send();
                  db_services.getOperation("testfunction").send();
                  }
                
                  private function swapResult(evt:ResultEvent):void
                  {
                      Alert.show(evt.result.status, "Result");
                  }
              ]]>
          </fx:Script>
          <mx:DataGrid x="10" y="10" width="494" height="442" dataProvider="{resultArr}" itemClick="clicky(event)">
              <mx:columns>
                  <mx:DataGridColumn headerText="ID" dataField="id" width="40"/>
                  <mx:DataGridColumn headerText="URL" dataField="url"/>
                  <mx:DataGridColumn headerText="Vis" dataField="visible" width="50"/>
              </mx:columns>
          </mx:DataGrid>
          <s:Label x="937" y="12" text="{selectedID}"  id="LoadedString_lbl"/>
      </s:Application>

       

      My php script is this

       

      <?php
      $hostname_conn = "localhost";
          $username_conn = "videochatadmin";
          $password_conn = "24627930";

          $conn = mysql_connect($hostname_conn, $username_conn, $password_conn);

          mysql_select_db("videochat");

          $sql ="UPDATE test SET visible ='yes' WHERE id = '3'";

          if (!mysql_query($sql, $conn))
          {
              echo "<status>not ok</status>";
          }
          else
          {
              echo "<status>ok</status>";
          }

      ?>


      But for some reason, sometimes it changes the value to yes, othertimes it dosent, bring the ppop up result box says ok.

       

      Any idea what i have done wrong ?

        • 1. Re: Datagrid and Update php script not working
          rootsounds Level 4

          So this is a PHP issue?

          • 2. Re: Datagrid and Update php script not working
            =VA=FyreHeart Level 2

            I haven't run this code to actually debug it, but a few things come to mind...

             

            First, you realize that your PHP mysql_query call returns a Boolean that indicates if the query ran or not, not whether the database was actually changed. You can have a successful UPDATE (i.e. mysql_query==true) that affects 0 database rows.

             

            Second, I'm a little surprised just wrapping "ok" in "<status>" tags works at all, since that's not well-formed XML. I don't know if that might be confusing ActionScript, but echoing well-formed XML can only help.

             

            Third, I would expect your clicky() function to actually change the value of the column, but I don't see it doing that. Something like ListEvent.target.value=ResultEvent.result.staus (using class names, not objects here) should probably be happening.

             

            Anyway, that's just a once over. Hope that helps.