7 Replies Latest reply on Sep 28, 2010 3:11 AM by l33tian

    flex and php connect

    flex_able Level 1

      flex code

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="send_data()">
          
          
          <mx:Script>
          <![CDATA[
              import mx.rpc.events.ResultEvent;
              import mx.controls.DataGrid
      
              private function send_data():void 
              {
                  userRequest.send();
              }
              
              private function handleResult(evt:ResultEvent):void
              {
                  dg1.dataProvider = evt.result.player;
              }
          ]]>
          </mx:Script>
          
          <mx:Label x="79" y="89" text="username"/>
          <mx:Label x="79" y="128" text="rolnumber"/>
          <mx:TextInput id="nm" x="153" y="87"/>
          <mx:TextInput x="153" y="126" id="roll"/>
          <mx:Button x="127" y="191" label="submit" id="sub" click="send_data()"/>
          
          <mx:HTTPService id="userRequest" result="handleResult(event)" url="http://localhost/connect.php" useProxy="false" method="POST">
              <mx:request xmlns="">
                  <username>{nm.text}</username><rollnumber>{roll.text}</rollnumber>
              </mx:request>
          </mx:HTTPService>
          
          <mx:DataGrid id="dg1" x="69" y="261">
              <mx:columns>
                  <mx:DataGridColumn headerText="Name" dataField="name"/>
                  <mx:DataGridColumn headerText="Roll" dataField="roll"/>
              </mx:columns>
          </mx:DataGrid>
      
      </mx:Application>

      php code

       

      <?php
       
          mysql_connect("localhost", "root", "") or die("cannot connect");
          mysql_select_db("std_db") or die("cannot select database");
       
          if ($_POST["username"])
          {
              $name = mysql_real_escape_string($_POST["username"]);
              $roll = mysql_real_escape_string($_POST["rollnumber"]);
       
              $query = "INSERT INTO student (name , roll) VALUES ('$name', '$roll')";
              
              if(mysql_query($query))
              {
                  echo "sucessfully inserted";
              }
              else
              {
                  echo" error occured";
              }
          }
          
          $query="SELECT * FROM student";
          $result = mysql_query($query);
          
          $num_rows = mysql_numrows($result);
              
          $i=0;
          
          while ($i < $num_rows) 
          {
              $getName = mysql_result($result,$i,"name");
              $getRoll = mysql_result($result,$i,"roll");
       
              print "<player><name>".$getName."</name><roll>".$getRoll."</roll></player>";
              $i++;
          }
          
      ?>

      webroot=c:\wamp\www

      rootURL=http://localhost

       

      the application dosent shows any error  bt it dosent add  data into the databasee... i m unable to get it why?